-
Notifications
You must be signed in to change notification settings - Fork 19.2k
docs: add robust parsing with automatic retry to structured outputs guide #33120
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
docs: add robust parsing with automatic retry to structured outputs guide #33120
Conversation
…uide - Add section on handling parsing errors in production - Show how to use OutputFixingParser for automatic retry on malformed outputs - Clarify that with_structured_output() doesn't provide built-in retry - Link to existing RetryOutputParser guide for advanced cases Related to langchain-ai#32977 - addresses need for better error handling documentation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
In production, LLMs may return malformed outputs. While `with_structured_output()` doesn't provide automatic retry on parsing errors, you can use `OutputFixingParser` for this: | ||
|
||
```python | ||
from langchain.output_parsers import OutputFixingParser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI we're not including this in langchain_v1 yet. We'll likely need to figure out how to have the same functionality exposed in v1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eyurtsev what is the recommended approach in V1? with_structured_output
?
@codeananda for your use cases, curious do any of these apply:
Basically if you know in which situations things are more likely to fail -- it'd be helpful for the maintainers :) |
None of the things you suggested apply.
Is that helpful? |
Closing this as current docs are frozen - new docs PRs should be opened against https://github.com/langchain-ai/docs Thank you! 🙏 |
Summary
Adds documentation for handling parsing errors in production when using structured outputs. This addresses a common issue where LLMs return malformed outputs that cause parsing failures.
Changes
OutputFixingParser
for automatic retry on malformed outputswith_structured_output()
doesn't provide built-in retry functionalityMotivation
In production environments, LLM outputs frequently fail to parse correctly due to network issues, incomplete responses, or model errors. This documentation helps users build more robust systems by showing them a simple pattern for automatic retry.
Related to #32977 - addresses the need for better error handling documentation in structured outputs.
Testing
Documentation-only change, no code modifications required.
Additional Context
This pattern has been invaluable in my own production systems. The current documentation doesn't make it clear that
with_structured_output()
lacks retry functionality, and users need to know aboutOutputFixingParser
as a solution.Future enhancement suggestion: Consider adding a
retry_on_parsing_error
parameter towith_structured_output()
to make this functionality built-in.