fix: validate tool args are dict in ToolEnv.env_response#960
Open
zamal-db wants to merge 1 commit intoPrimeIntellect-ai:mainfrom
Open
fix: validate tool args are dict in ToolEnv.env_response#960zamal-db wants to merge 1 commit intoPrimeIntellect-ai:mainfrom
zamal-db wants to merge 1 commit intoPrimeIntellect-ai:mainfrom
Conversation
When a model produces double-encoded JSON, json.loads succeeds but returns a str instead of a dict. This crashes the RL training run when the str is unpacked as **kwargs. StatefulToolEnv already has this validation (lines 141-147), but ToolEnv was missing it. This aligns both env_response methods. Closes PrimeIntellect-ai#562
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While training a tool-calling agent with ToolEnv, I hit a crash mid-rollout caused by a model (Qwen3-4B) producing double-encoded JSON tool arguments. json.loads succeeds but returns a str instead of a dict, which then crashes when unpacked as **kwargs in call_tool.
StatefulToolEnv.env_response already guards against this (lines 141-147), but ToolEnv.env_response was missing the same check. This aligns both methods.
Changes:
Closes #562
Type of Change
Testing
uv run pytestlocally.Checklist
Note
Low Risk
Small, localized input-validation change in tool-call parsing plus tests; behavior only differs for malformed/non-dict tool arguments.
Overview
Prevents
ToolEnv.env_responsefrom crashing when a model returns double-encoded JSON tool arguments by validating thatjson.loads(tool_call.arguments)produces adictand treating non-dicts as a parse error.Adds coverage for this case with two new tests: one verifying rollouts stop with
ToolParseErrorwhenValueErroris instop_errors, and another ensuring the env returns a tool error message and continues when it is not.Written by Cursor Bugbot for commit 0d5da8c. This will update automatically on new commits. Configure here.