Skip to content

refactor(llm): unify ToolError contract for arg validation#1607

Open
rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
touts-undulate-earplug
Open

refactor(llm): unify ToolError contract for arg validation#1607
rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
touts-undulate-earplug

Conversation

@rosetta-livekit-bot
Copy link
Copy Markdown
Contributor

@rosetta-livekit-bot rosetta-livekit-bot Bot commented May 26, 2026

Summary

Unifies tool-argument validation under a single ToolError contract owned by prepare_function_arguments, and fixes a malformed-JSON propagation bug along the way.

  • prepare_function_arguments wraps ValidationError / ValueError / TypeError as ToolError("Error parsing arguments for ..."), so the message the LLM sees is owned in one place.
  • Accepts an optional fnc_call: FunctionCall | None parameter. When provided and json_arguments is a string, the canonical JSON (post json_repair) is written back to fnc_call.arguments before pydantic validation runs. This way, even when validation later fails, the conversation history holds valid JSON instead of the broken raw payload — without this, providers like Vertex/OpenAI reject the next request with a 5xx when re-serializing it (#5807 review).
  • execute_function_call drops its dedicated (ValidationError, ValueError) branch — one prepare_function_arguments(..., fnc_call=fnc_call) call covers both parse failures and validation failures.
  • ToolProxyToolset._handle_call drops its own try/except wrapper and passes the parameters dict directly (no extra json.dumps).
  • Pure-validation callers (judge.py, async_toolset.py, run_result.py) are unchanged — they just don't pass fnc_call.

Extracted from #5711.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 26, 2026

⚠️ No Changeset found

Latest commit: 2637fbd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

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.

0 participants