Skip to content

fix: accept fenced JSON output in raw JSON mode for OpenAI-compatible backends - #444

Open
Samay10 wants to merge 3 commits into
google:mainfrom
Samay10:fix-vllm-openai-json-compatibility
Open

Samay10 wants to merge 3 commits into
google:mainfrom
Samay10:fix-vllm-openai-json-compatibility

Conversation

@Samay10

@Samay10 Samay10 commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes issue #414 where vLLM/lmdeploy OpenAI-compatible backends may return fenced JSON output even when LangExtract is configured for raw JSON mode. This updates langextract/core/format_handler.py so FormatHandler._extract_content() detects and strips a single fenced JSON block when use_fences=False, and adds a regression test for fenced JSON output in raw JSON mode.

Fixes #414

Bug fix

How Has This Been Tested?

  • Added regression test in tests/format_handler_test.py
  • Verified modified files compile with python3 -m py_compile
  • Full unit tests not run in the current environment due to missing absl dependency

Checklist:

  • I have read and acknowledged Google's Open Source Code of conduct.
  • I have read the Contributing page, and I either signed the Google Individual CLA or am covered by my company's Corporate CLA.
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach.
  • I have made any needed documentation changes, or noted in the linked issue(s) that documentation elsewhere needs updating.
  • I have added tests, or I have ensured existing tests cover the changes
  • I have followed Google's Python Style Guide and ran pylint over the affected code.

@github-actions github-actions Bot added the size/XS Pull request with less than 50 lines changed label Apr 15, 2026
Samay10 added 2 commits April 15, 2026 23:19
- Precompute strip_text to consolidate duplicate returns (7->6)
- Fixes lint-src CI failure for google#414
@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 1 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 9 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 15 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 16 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 18 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 23 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

5 similar comments
@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 23 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 23 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 23 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 23 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 23 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 26 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

2 similar comments
@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 26 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 26 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 33 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

1 similar comment
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 33 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 34 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 35 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

2 similar comments
@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 35 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 35 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 39 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 41 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 42 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 43 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 51 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@BichengWang BichengWang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed head ace8d09840b4a282923fa86ac1a6d5292caa7861.

[P2] Preserve backticks inside valid raw JSON before attempting fence recovery (new raw-mode branch). _FENCE_RE.finditer(text) also matches backticks inside JSON string values. With the default strict_fences=False, the single-match fallback discards the surrounding valid JSON and tries to parse only that match's body:

import json
from langextract.core.format_handler import FormatHandler

handler = FormatHandler(use_fences=False)
payload = {"extractions": [{"snippet": "```hello```"}]}
assert handler.parse_output(json.dumps(payload)) == payload["extractions"]

This succeeds at the PR's merge base 8c86bf6fa3d2c0b1196409e36218a2de1b84f860 but raises FormatParseError: Failed to parse JSON content: Expecting value: line 1 column 1 (char 0) at this head. A raw example produced by format_extraction_example() with the same extraction text also fails to parse back. Please preserve already valid raw JSON, for example by attempting raw parsing before fence recovery or limiting recovery to an outer fence, and add regression coverage for backticks within extraction values alongside the outer-fence test.

Validation at this exact head: Python 3.11.17; python -m pytest tests -m "not live_api and not requires_pip and not integration" -q completed with 443 passed, 1 deselected, 29 subtests passed. Two additional probes (raw JSON above and formatter round trip) failed; the outer fenced JSON case passed. Dependencies came from the local cache; dotenv loading was disabled and provider credential variables removed for the suite. Pyink and all three import contracts passed. Full isort reported ordering in plugins.py and providers/__init__.py; source Pylint reported R0911 in _extract_content, and test Pylint reported argument mismatches in test_gemini_batch_api.py. No live services, other Python versions, or merge with current main were tested.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 56 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 56 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 62 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 69 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

1 similar comment
@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 69 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 77 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 88 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Pull request with less than 50 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ResolverParsingError when using vLLM/lmdeploy as backend (Qwen3-32B-GPTQ)

2 participants