generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 425
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Problem Statement
The structured_output
doesn't always work on the first try, and throws an exception when there are validation errors (especially with more complicated output schemas). I've found that if you try/retry once, and provide the agent the exception from the first iteration, it will self heal appropriately. It would be nice if this were built-in to the structured_output
function, e.g. something like structured_output(max_retries=3)
Proposed Solution
Here is some sample code which works:
# first I have the agent do some analysis, then I do:
try:
result = agent.structured_output(
OutputSchemaModel,
"Based on your prior analysis, generate a structured OutputSchemaModel output.",
)
except Exception as e:
result = agent.structured_output(
OutputSchemaModel,
f"Try again to generate a structured OutputSchemaModel output. Your previous attempt failed with this exception: {e}",
)
return result
Use Case
Use case for people who want reliable structured output with reduced probability of the structured_output
function throwing an exception when it fails.
Alternatives Solutions
No response
Additional Context
No response
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request