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

fix(langchain): Fix structured parser with triple backticks, adds tests #7199

Merged
merged 2 commits into from
Nov 17, 2024

Conversation

johnguirgis
Copy link
Contributor

Fixes #6734

Corrects an issue where the output parser naïvely attempts to parse contents of triple backticks as JSON.

  1. Output parser falls back to parse the entire string when extracting from within triple backticks fails
  2. Adds tests to account for different backtick positions in JSONs

Initial implementation to handle JSONs with triple backticks inside their values.
Copy link

vercel bot commented Nov 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Nov 15, 2024 3:07am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Nov 15, 2024 3:07am

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. auto:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Nov 13, 2024
@harrisbchong
Copy link

To maintain backwards compatibility, we modified our solution attempt at #6734 to leave the original parsing and behaviour in the first try block. Instead, we move our new parsing code inside the catch block, ensuring it executes only when the original code fails. The logic within the new try block is as follows: we know parsing the contents within the brace has failed, meaning that the only hope is to parse the string as whole (while trimming the leading or trailing whitespace).

Copy link
Collaborator

@jacoblee93 jacoblee93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, seems reasonable!

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label Nov 17, 2024
@jacoblee93 jacoblee93 changed the title Fix structured parser with triple backticks fix(langchain): Fix structured parser with triple backticks, adds tests Nov 17, 2024
@jacoblee93 jacoblee93 merged commit 986ab14 into langchain-ai:main Nov 17, 2024
30 checks passed
FilipZmijewski pushed a commit to FilipZmijewski/langchainjs that referenced this pull request Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature lgtm PRs that are ready to be merged as-is size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StructuredOutputParser can't handle nested triple backticks
3 participants