From 4eaa5ca6510622cb0006bcfee5947b17859ac8c7 Mon Sep 17 00:00:00 2001 From: Raghavendra Vedula Date: Wed, 22 Jul 2026 08:25:25 -0700 Subject: [PATCH] Treat partial_json_parser AssertionError as incomplete JSON (#31975) --- python/sglang/srt/function_call/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/python/sglang/srt/function_call/utils.py b/python/sglang/srt/function_call/utils.py index f36179a9f..072bf50a2 100644 --- a/python/sglang/srt/function_call/utils.py +++ b/python/sglang/srt/function_call/utils.py @@ -209,6 +209,15 @@ def _partial_json_loads(input_str: str, flags: Allow) -> Tuple[Any, int]: obj, end = JSONDecoder().raw_decode(input_str, start) return obj, end raise + except AssertionError as e: + # partial_json_parser.fix_fast() asserts on some partial/ambiguous inputs + # (e.g. trailing non-whitespace after an otherwise-fixable prefix) instead + # of signaling "incomplete". Convert to JSONDecodeError so streaming + # callers treat it as not-yet-complete (wait for more tokens) rather than + # raising and failing the request. + raise JSONDecodeError( + "partial_json_parser assertion (treat as incomplete)", input_str, 0 + ) from e def _is_complete_json(input_str: str) -> bool: