feat(llm): recover outer JSON span when fence stripping yields non-JSON#2610
Merged
Conversation
Grafts the parse-validated fallback from #2557 onto the line-based fence stripper merged in #2563: after stripping, if the candidate is not valid JSON (partial/absent fence, prose-wrapped or truncated output), fall back to the outermost parseable {..}/[..] span. Never returns a worse candidate than the raw content.
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.
Builds on #2563 (line-based fence stripping) by grafting the most valuable idea from #2557 (parse-validated fallback) — so the two approaches compose instead of competing.
What
_strip_code_fencesnow:{..}/[..]span (from Harden fenced JSON parsing #2557)This recovers cases the line-based stripper alone gives up on: missing closing fence, JSON wrapped in prose, truncated output.
Tests
Extended
test_strip_code_fences.py(13 pass): missing-closing-fence recovery, prose-wrapped JSON recovery, non-JSON fence left for retry, plus the existing inner-backtick + fence cases.Supersedes the overlapping #2557 (which conflicted after #2558).