Skip to content
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

enhance json parsing #4125

Closed
wants to merge 2 commits into from
Closed

enhance json parsing #4125

wants to merge 2 commits into from

Conversation

iEgit
Copy link

@iEgit iEgit commented Mar 5, 2025

This PR improves the JSON parsing logic in StructuredOutputParser.ts to handle malformed JSON responses from LLMs more effectively.

Changes:
• Fixed JSON extraction logic:
• Previously, JSON extraction relied on splitting text using code block markers (`json).
• Now, it uses a regex (/(?:^[^{[])|(?:[^}\]]$)/g) to remove any leading or trailing non-JSON content, ensuring a more robust parsing approach.

Why this change?
• The previous approach failed in some edge cases where JSON responses did not follow the expected format.
• The new regex-based approach ensures that only valid JSON content is passed to jsonrepair, reducing the likelihood of parsing errors.

Testing:
• Manually tested with different malformed JSON outputs to verify correct parsing.
• Ensured existing functionality remains intact.

@iEgit iEgit changed the title enhance json parse enhance json parsing Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant