fix(nodes): tolerate doubled-brace JSON output from models like DeepSeek#1085
Merged
VinciGit00 merged 1 commit intoJun 11, 2026
Merged
Conversation
The default GenerateAnswerNode format_instructions show the expected shape as
{{"content": ...}} (LangChain's escaped braces). Strongly instruction-following
models emit single braces, but some models (notably DeepSeek) copy the doubled
braces verbatim, yielding {{"content": ...}} which JsonOutputParser rejects with
'Invalid json output'.
Add TolerantJsonOutputParser, a JsonOutputParser subclass that retries once with a
single layer of wrapping braces removed, only on the parse-failure path. Behaviour
is unchanged for any model already returning valid JSON. Use it in the schema-less
branch of GenerateAnswerNode. Adds unit tests.
VinciGit00
approved these changes
Jun 11, 2026
github-actions Bot
pushed a commit
that referenced
this pull request
Jun 11, 2026
## [2.2.0-beta.4](v2.2.0-beta.3...v2.2.0-beta.4) (2026-06-11) ### Bug Fixes * **nodes:** tolerate doubled-brace JSON output from models like DeepSeek ([#1085](#1085)) ([aaa5d2c](aaa5d2c))
|
🎉 This PR is included in version 2.2.0-beta.4 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GenerateAnswerNode fails with
OutputParserException: Invalid json outputwhen the LLM returns its JSON wrapped in doubled braces, e.g.{{"content": "..."}}. This happens reliably with DeepSeek (deepseek/deepseek-chat) and intermittently with other less strict models.Root cause
The schema-less
format_instructionsshow the expected shape as:Those doubled braces are LangChain template escaping for a single literal
{ }. GPT-4o-class models follow the instruction and emit single braces, but some models (notably DeepSeek) copy the doubled braces verbatim into their answer, which is not valid JSON, soJsonOutputParserraises.Fix
Add
TolerantJsonOutputParser, a smallJsonOutputParsersubclass that, only on the parse-failure path, retries once with a single layer of wrapping braces removed. Behaviour is unchanged for any model already returning valid JSON (the happy path goes straight through the parent parser). It is used in the schema-less branch ofGenerateAnswerNode.scrapegraphai/utils/output_parser.py— newTolerantJsonOutputParser+_strip_doubled_braceshelperscrapegraphai/nodes/generate_answer_node.py— use it in the non-schema branchtests/utils/output_parser_test.py— 7 unit tests (clean JSON unchanged, doubled-brace recovery, whitespace, irrecoverable output still raises)Reproduction (before this change)
After: returns the parsed dict as expected.
Testing
Suggested labels:
bug,size:S