Skip to content

[Engine] Opt-in LaTeX-safe JSON recovery for json_object responses (LightRAG VLM) #2893

Closed

Description

@BoysGameStudio

Summary

When a vision-language model generates JSON containing an unescaped LaTeX
backslash, Strata's response_format: {"type":"json_object"} validation
rejects the completion with HTTP 502 (structured_output_failed).

This breaks LightRAG's multimodal PDF ingestion because LightRAG already
implements tolerant JSON parsing and LaTeX escape recovery, but Strata
rejects the response before LightRAG can access the generated text.

The issue has been reproduced using the same image and prompt.

Environment

  • Strata v0.1.44.1 (Strata-NVFP4 fork)
  • Qwen3.8-Flash-Next NVFP4
  • GPU vision enabled
  • LightRAG v1.5.7
  • MinerU PDF pipeline
  • OpenAI-compatible Chat Completions API

Minimal Reproduction

Model-generated content:

{"name":"alpha coefficient","type":"diagram","description":"Coefficient \alpha_0"}

The sequence \a is not a valid JSON escape.

This can also be reproduced directly against Strata's validator:

from serve.structured import _ObjectOnly, validated_json

raw = r'{"name":"alpha coefficient","type":"diagram","description":"Coefficient \alpha_0"}'

print(validated_json(raw, _ObjectOnly(), "stop"))

Actual Behavior

  • Strict JSON parsing fails.
  • Strata returns HTTP 502 (structured_output_failed).
  • The original generated response is unavailable to LightRAG.
  • LightRAG retries the failed provider request.
  • The document eventually enters the FAILED state.

Expected Behavior

An optional recovery mode could repair unambiguous LaTeX escaping errors
before strict validation.

For example:

{"name":"alpha coefficient","type":"diagram","description":"Coefficient \\alpha_0"}

The repaired output should still pass strict JSON validation before
being returned to the client.

Proposed Solution

Introduce an opt-in, conservative JSON recovery mechanism for
response_format=json_object.

Suggested behavior:

  1. Preserve existing strict validation by default.
  2. Attempt limited LaTeX-aware repair when explicitly enabled.
  3. Validate the repaired JSON using the existing validator.
  4. Return canonical JSON only after successful validation.
  5. Continue returning HTTP 502 for unrecoverable output.
  6. Preserve existing json_schema behavior.

The implementation must also account for LaTeX commands such as:

  • \alpha
  • \beta
  • \frac
  • \tau
  • \nabla

Some commands conflict with valid JSON escape sequences, so simply
doubling every backslash is unsafe.

Regression tests should cover legitimate JSON escapes, already-correct
LaTeX escaping, duplicate keys, invalid constants, and truncated output.

Related Issues and PRs

Constrained decoding may prevent syntactically invalid JSON, but it does
not necessarily preserve LaTeX semantics when a model emits JSON-valid
escape sequences.

This feature would improve compatibility with LightRAG and other
applications processing mathematical or technical documents.

Retest (2026-10-21)

Retested on Strata 0.2.0-beta (source, tag v0.2.0-beta) and on the current release (Strata 0.2.1.4
source build, engine strata 0.1.46.3). Still reproduces on both; serve/structured.py is unchanged
since v0.1.44.1.

  • GPU: RTX 5090 32 GB, driver 615.71.10. Memory: 121 GiB. System: Ubuntu 26.04.1, kernel 7.0.0-38.
  • What I see: with response_format: {"type":"json_object"}, a completion containing
    {"description":"$\alpha_0 > 1$"} gives HTTP 502 structured_output_failed (validator:
    Invalid \escape), and the text never reaches the client. Reproduced on both with the built-in mock
    engine (--engine mock --script), which is the same validation path. Not reproduced with a real
    model: my runs escaped the backslashes correctly, so the rejection comes from the validator, not the
    model.
  • The 502 says nothing about what the model wrote, so the caller cannot recover the text itself.

Activity

  1. Niko1221 commented on Oct 19, 2026

    @Niko1221
    Owner

    Thanks for taking the time to report this.

    We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected.

    To reopen it takes about two minutes:

    1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see.
    2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
    3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
    4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

    The rules are in CONTRIBUTING.md.

  2. changed the title [-][Feature Request] Opt-in LaTeX-safe JSON recovery for json_object responses (LightRAG VLM)[/-] [+][Engine] Opt-in LaTeX-safe JSON recovery for json_object responses (LightRAG VLM)[/+] on Oct 21, 2026
  3. BoysGameStudio commented on Oct 21, 2026

    @BoysGameStudio
    Author

    Retested on a source build of the current release — still reproduces.

    • Strata: v0.2.1.4 source build, engine strata 0.1.46.3 (CUDA 13.4, sm_120). serve/structured.py
      is unchanged since v0.1.44.1.
    • GPU: RTX 5090 32 GB, driver 615.71.10. Memory: 121 GiB. System: Ubuntu 26.04.1, kernel 7.0.0-38.
    • What I see: with response_format: {"type":"json_object"}, a completion containing
      {"description":"$\alpha_0 > 1$"} gives HTTP 502 structured_output_failed and the text never
      reaches the client. Reproduced with the built-in mock engine (--engine mock --script), which is the
      same validation path. Not reproduced with a real model: my runs escaped the backslashes correctly, so
      the rejection comes from the validator, not the model.
    • Not tested against the beta binaries; this is a build of the release tag's source.
  4. BoysGameStudio commented on Oct 21, 2026

    @BoysGameStudio
    Author

    /reopen

  5. github-actions commented on Oct 21, 2026

    @github-actions

    Not reopened yet. Still missing:

    • Re-test on Strata 0.2.0-beta and name that version in the issue. If it no longer happens, say so in a comment instead.

    Edit the issue and comment /reopen again. Details: CONTRIBUTING.md

  6. BoysGameStudio commented on Oct 21, 2026

    @BoysGameStudio
    Author

    /reopen

  7. github-actions commented on Oct 21, 2026

    @github-actions

    Not reopened yet. Still missing:

    • Re-test on Strata 0.2.0-beta and name that version in the issue. If it no longer happens, say so in a comment instead.

    Edit the issue and comment /reopen again. Details: CONTRIBUTING.md

  8. BoysGameStudio commented on Oct 21, 2026

    @BoysGameStudio
    Author

    /reopen

  9. github-actions commented on Oct 21, 2026

    @github-actions

    Reopened, thank you. A maintainer will pick it up from here.

  10. Niko1221 commented on Oct 27, 2026

    @Niko1221
    Owner

    Thank you. Fixed in 0.2.7: Opt-in LaTeX-safe JSON recovery for structured output.

    Release: https://github.com/Niko1221/Strata/releases/tag/v0.2.7

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions