-
Notifications
You must be signed in to change notification settings - Fork 458
Description
Problem Statement
Structured_output requests [seem] to be able to re-try forever when a validation error is thrown.
NOTE: There's already an open PR to already address this: #1026
Edit: Whoops, now closed and apparently for the structured_output implementation prior to v1.14.0
But opening an issue in hopes of prioritization / discussion as I'd rather keep non-code discussions outside of PRs.
Proposed Solution
A max-retries limit is the preferred solution.
Use Case
Prevent an infinite loop of LLM re-try attempts for prompts that are at risk of having LLMs not be able to produce the expected output.
Alternatives Solutions
No response
Additional Context
First behavior I tried with the new structured_output implementation was to update a test pydantic model with:
class TestModel(BaseModel):
# [...]
give_me_a_string: int...Just corner-case testing and was not surprised it was not able to handle this. But would prefer confidence that this will not happen in production.
Stream:
ERROR:strands.tools.structured_output.structured_output_tool:tool_name=<TestModel> | structured output validation failed | error_message=<Validation failed for TestModel. Please fix the following errors:
- Field 'give_me_a_string': Field required>
<thinking> It there was an error due to a missing field in the tool call. I will correct the error and resubmit the analysis without the unnecessary field. </thinking>
Tool #2: TestModel
ERROR:strands.tools.structured_output.structured_output_tool:tool_name=<TestModel> | structured output validation failed | error_message=<Validation failed for TestModel. Please fix the following errors:
- Field 'give_me_a_string': Field required>
It went on to re-try 40 times until being rate limited by AWS bedrock.
This is concerning and we'd love to see the max_retries or a more defensive way to handle this (still testing, so maybe it's possible).