Skip to content

Bug: fenced JSON parsing rejects triple backticks inside extraction strings #581

Description

@BichengWang

Describe the overall issue and situation

Extracting Markdown code blocks can fail even when the model returns valid fenced JSON. FormatHandler treats triple backticks inside a JSON string as output delimiters. Its own format_extraction_example() output therefore cannot be parsed back with the default settings when an extraction contains a Markdown code block.

Expected behavior

The single outer JSON block should parse, preserving backticks inside JSON string values.

Actual behavior

The reproduction raises FormatParseError: Multiple fenced blocks found. Expected exactly one. There is only one outer output block; the other backticks belong to the extraction value.

Steps to reproduce the issue

Run this offline:

from langextract.core import data, format_handler

value = "```python\nprint(1)\n```"
extractions = [data.Extraction(
    extraction_class="code", extraction_text=value
)]
handler = format_handler.FormatHandler()
output = handler.format_extraction_example(extractions)
print(output)
print(handler.parse_output(output))

As a control, using FormatHandler(use_fences=False) for both formatting and parsing preserves the same value successfully.

Any additional content

Reproduced on main 3a68580f0aede0e96a2e1e03daa2a5f4011e4fcd, Python 3.11.17, macOS, with no model/API calls. The fence regex matches delimiters inside the JSON string before JSON parsing runs. This concerns fenced output containing literal backticks; #414 / #444 concern receiving an outer fenced block when raw JSON mode was requested.

Activity

  1. mohmedmm commented on Nov 2, 2026

    @mohmedmm

    opened #604 with a fix anchoring code fence delimiters.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions