Skip to content

fix(core): catch ValueError and TypeError in Refine structured output handlers#21237

Closed
GopalGB wants to merge 2 commits intorun-llama:mainfrom
GopalGB:fix/refine-catch-value-type-errors
Closed

fix(core): catch ValueError and TypeError in Refine structured output handlers#21237
GopalGB wants to merge 2 commits intorun-llama:mainfrom
GopalGB:fix/refine-catch-value-type-errors

Conversation

@GopalGB
Copy link
Copy Markdown

@GopalGB GopalGB commented Mar 31, 2026

Summary

  • Broadens exception handling in Refine response synthesizer to catch ValueError and TypeError alongside ValidationError
  • Prevents query failures when the function-calling structured-output path raises these exceptions (e.g., missing tool calls, non-BaseModel outputs)
  • Applied to all four try/except blocks: _give_response_single, _refine_response_single, and their async counterparts

Root Cause

After changes in #21036, the function-calling structured-output path can raise:

  • ValueError for missing/failed tool calls
  • TypeError for non-BaseModel tool outputs

These were not caught by the except ValidationError clause, causing the query to fail instead of falling through to the existing warning/fallback path.

Test Plan

  • Verified all four except blocks updated consistently
  • No behavior change for ValidationError — still caught and logged as before
  • ValueError and TypeError now trigger the same warning path instead of propagating

Fixes #21089

GopalGB added 2 commits March 31, 2026 18:52
…th invalid IDs

Build a filtered list of valid node IDs instead of mutating the input
list during iteration. The previous approach could skip elements when
removing items from a list while iterating over it, allowing invalid
IDs to reach _index_struct.delete_nodes() and cause a KeyError.

Fixes run-llama#21066
… handlers

The function-calling structured-output path can raise ValueError (for
missing/failed tool calls) and TypeError (for non-BaseModel tool outputs)
in addition to ValidationError. These were uncaught, causing queries to
fail instead of falling through to the warning path.

Broadens the except clause in all four structured response try/except
blocks (_give_response_single, _refine_response_single, and their
async counterparts) to also catch ValueError and TypeError.

Fixes run-llama#21089
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 31, 2026
@gautamvarmadatla
Copy link
Copy Markdown
Contributor

hi @GopalGB there is already a PR open on this issue since couple of weeks with same changes...

@GopalGB
Copy link
Copy Markdown
Author

GopalGB commented Apr 1, 2026

Hey @gautamvarmadatla, my bad — should have checked open PRs before picking up the issue. Closing this one. Your PR has priority.

@GopalGB GopalGB closed this Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Refine does not catch ValueError/TypeError from tool-calling structured outputs

2 participants