Skip to content

fix(bedrock): parse single JSON tool calls whose arguments are an object - #1070

Open
alexg0405 wants to merge 1 commit into
evalstate:mainfrom
alexg0405:fix/bedrock-single-json-tool-call
Open

alexg0405 wants to merge 1 commit into
evalstate:mainfrom
alexg0405:fix/bedrock-single-json-tool-call

Conversation

@alexg0405

Copy link
Copy Markdown

Fixes #1068

_single_json_tool_call matched the tool call with \{[^}]*"name"[^}]*"arguments"[^}]*\}. [^}]* stops at the first }, which closes arguments when it is an object, so the match was cut short, json.loads failed and the call was dropped.

The regex now only finds where the object starts, and json.JSONDecoder.raw_decode parses from there to its real end, so object arguments (nested braces, braces inside strings) come through whole. Malformed JSON still raises, so the existing warning in _logged_single_json_tool_call is unchanged.

Tests: parametrized cases for _parse_system_prompt_tool_response covering the issue's inputs, nested arguments with a } in a string, and an object without arguments. The object-argument cases fail on main and pass with this change. Format, lint, typecheck and cpd checks pass.

The single-object fallback in _single_json_tool_call matched the call with
\{[^}]*"name"[^}]*"arguments"[^}]*\}. [^}]* stops at the first "}", which
closes "arguments" when it is an object, so json.loads failed and the tool
call was dropped.

Use the regex only to find where the object starts and let
json.JSONDecoder.raw_decode find where it ends. Malformed JSON still raises,
so the existing warning in _logged_single_json_tool_call is unchanged.

This branch has not been deployed

No deployments
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.

Bedrock system-prompt tool parsing drops a single JSON tool call whose arguments are an object

1 participant