Skip to content

How would you handle Pydantic output_type validation and retries? #530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jackien1 opened this issue Apr 16, 2025 · 1 comment
Open

How would you handle Pydantic output_type validation and retries? #530

jackien1 opened this issue Apr 16, 2025 · 1 comment
Labels
question Question about using the SDK

Comments

@jackien1
Copy link

If you want to double check that a property like "pdf_id" that the AI spits out in structured output exists in the database would you just run a while loop checker with max iterations, dynamic model creation of enums or literals, or use AfterValidator? Not sure what is the best practice for this agentic SDK.

@jackien1 jackien1 added the question Question about using the SDK label Apr 16, 2025
@rm-openai
Copy link
Collaborator

I think the most straightforward thing would be to take the final output, so the validation, and it the validation failed - re-run the agent with the previous input list plus a new message saying that the output was invalid. Something like "pdf didn't exist, please fix"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about using the SDK
Projects
None yet
Development

No branches or pull requests

2 participants