Skip to content

fix: don't crash rollouts on malformed tool-call arguments and missing message content - #1180

Merged
bxyu-nvidia merged 2 commits into
NVIDIA-NeMo:mainfrom
jthomson04:jthomson04/fix-malformed-tool-call-args
Apr 30, 2026
Merged

bxyu-nvidia merged 2 commits into
NVIDIA-NeMo:mainfrom
jthomson04:jthomson04/fix-malformed-tool-call-args

Conversation

@jthomson04

Copy link
Copy Markdown
Contributor

Summary

Two small defensive fixes that came up while running rollouts; both were triggering crashes on otherwise-recoverable model outputs.

  • simple_agent: when the model emits tool-call arguments that aren't valid JSON, the agent crashed the whole rollout batch on json.loads(output_function_call.arguments). Catch JSONDecodeError/TypeError, surface the parse error back to the model as a function_call_output, and let the loop continue (it will either self-correct on the next turn or terminate naturally with a low reward). Adds a unit test exercising this path.
  • vllm_model: in the reasoning-parser branch, choice_dict["message"]["content"] or "" would KeyError if the upstream response omitted the content key entirely (some vLLM responses do this when only reasoning_content is set). Switched to choice_dict["message"].get("content") or "" so a missing key behaves the same as None.

Both are pulled out of a longer-running branch as standalone, isolated fixes; no behavior changes for the happy paths.

Test plan

  • pytest responses_api_agents/simple_agent/tests/test_app.py — all 6 tests pass, including the new test_responses_continues_on_malformed_tool_call_arguments.
  • pytest responses_api_models/vllm_model/tests/test_app.py — all 66 tests pass.

🤖 Generated with Claude Code

…g message content

simple_agent: when a model produces tool-call arguments that are not valid
JSON, the agent crashed the entire batch on `json.loads`. Catch the parse
error and feed it back as a `function_call_output` so the rollout can
continue (or terminate naturally with a low reward). Adds a unit test.

vllm_model: in the reasoning-parser code path, prepending the wrapped
reasoning to `choice_dict["message"]["content"]` would `KeyError` if the
upstream response omitted `content` entirely. Use `.get("content")` so a
missing key behaves the same as `None`.

Signed-off-by: jthomson04 <[email protected]>
@bxyu-nvidia
bxyu-nvidia requested a review from jkyi-nvidia April 29, 2026 21:39
…lways shown

Per review feedback: str(e) is empty for exceptions constructed without
args (e.g. `Exception()` -> ""), which would leave the model staring at
"Invalid tool call arguments: " with no signal about what went wrong.
repr(e) always includes the exception class name, so the model sees
"...JSONDecodeError('Expecting value: line 1 column 1 (char 0)')" or at
worst "...JSONDecodeError()" rather than an empty string.

Signed-off-by: jthomson04 <[email protected]>
@bxyu-nvidia
bxyu-nvidia merged commit 1dc5671 into NVIDIA-NeMo:main Apr 30, 2026
7 checks passed
cmunley1 pushed a commit that referenced this pull request May 1, 2026
…g message content (#1180)

## Summary

Two small defensive fixes that came up while running rollouts; both were
triggering crashes on otherwise-recoverable model outputs.

- **`simple_agent`**: when the model emits tool-call `arguments` that
aren't valid JSON, the agent crashed the whole rollout batch on
`json.loads(output_function_call.arguments)`. Catch
`JSONDecodeError`/`TypeError`, surface the parse error back to the model
as a `function_call_output`, and let the loop continue (it will either
self-correct on the next turn or terminate naturally with a low reward).
Adds a unit test exercising this path.
- **`vllm_model`**: in the reasoning-parser branch,
`choice_dict["message"]["content"] or ""` would `KeyError` if the
upstream response omitted the `content` key entirely (some vLLM
responses do this when only `reasoning_content` is set). Switched to
`choice_dict["message"].get("content") or ""` so a missing key behaves
the same as `None`.

Both are pulled out of a longer-running branch as standalone, isolated
fixes; no behavior changes for the happy paths.

## Test plan

- [x] `pytest responses_api_agents/simple_agent/tests/test_app.py` — all
6 tests pass, including the new
`test_responses_continues_on_malformed_tool_call_arguments`.
- [x] `pytest responses_api_models/vllm_model/tests/test_app.py` — all
66 tests pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: jthomson04 <[email protected]>
Signed-off-by: cmunley1 <[email protected]>
tdene added a commit that referenced this pull request Jul 30, 2026
Follow-up to #2139 and #1180

Signed-off-by: Teodor-Dumitru Ene <[email protected]>
OlegSudakov pushed a commit to OlegSudakov/Gym that referenced this pull request Aug 7, 2026
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.

2 participants