Skip to content

Keep raw string for tool-call args that literal_eval to non-JSON types#37

Open
nightlessbaron wants to merge 2 commits into
prodfrom
fix/literal-eval-nonjson-tool-args
Open

Keep raw string for tool-call args that literal_eval to non-JSON types#37
nightlessbaron wants to merge 2 commits into
prodfrom
fix/literal-eval-nonjson-tool-args

Conversation

@nightlessbaron

Copy link
Copy Markdown

_deserialize_glm_value falls back to ast.literal_eval for arg values that aren't valid JSON, which can return types JSON can't represent. Seen in an RL run: the model wrote {480, 630} (meant [480, 630]), literal_eval turned it into a Python set, and json.dumps(args) in _extract_ifm raised TypeError — dropping every tool call in that turn.

Accept the literal_eval result only if it round-trips through json.dumps, otherwise keep the raw string, so a single malformed arg degrades to a string value instead of killing the whole parse. Added a regression test (fails before, passes after; full detector suite green).

@nightlessbaron nightlessbaron requested a review from a team July 2, 2026 08:37
Comment thread python/sglang/srt/function_call/multi_format_detector.py
Comment thread python/sglang/srt/function_call/multi_format_detector.py
Comment thread python/sglang/srt/function_call/multi_format_detector.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants