Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Structured Output Repair

Structured Output Repair extracts and repairs JSON and YAML generated by language models. It runs locally on text you already have, using Python and deterministic parsing and repair rules. Use it between a model response and your application's own schema or domain validation.

Install

The first PyPI beta is planned as structured-output-repair==0.3.0b1. Once it is published, install it in a fresh Python 3.11–3.13 environment:

python -m venv .venv
.venv/bin/python -m pip install structured-output-repair==0.3.0b1

On Windows, use .venv\Scripts\python.exe. To try a local beta build before publication, install its structured_output_repair-0.3.0b1-py3-none-any.whl by path instead.

The distribution is named structured-output-repair. The Python import remains llm_output_repair and the diagnostic command remains llm-repair. The PyPI project named llm-output-repair belongs to a different project. Its 0.2.0 source distribution uses llm_json_repair and declares no console commands. Use a clean environment for Structured Output Repair, especially if you previously installed a Git-based distribution of this repository under the old name. The old Git distribution shares the namespace and CLI.

Quick start

from llm_output_repair import repair

result = repair('Result:\n{"items": [1,,2,], "ok": true}')
assert result == {"items": [1, 2], "ok": True}

repair() returns the decoded Python value. It defaults to SAFE for JSON and TOLERANT for YAML. The named helpers repair_json() and repair_yaml() retain their historical TOLERANT defaults.

Choose a policy

Policy JSON YAML
strict Decode without repair, with duplicate-key and nonstandard constant rejection. Supports objects, arrays and scalars through the value-returning helpers. One document through PyYAML's safe_load, with native YAML value types.
safe Object root only. Recover one object from supported presentation and apply supported local syntax repairs with data-preservation checks. Reject missing or competing structured content, duplicate keys, ambiguous repairs and floats that decode to infinity. Unavailable.
tolerant Legacy heuristic extraction and repair. Can select a fragment, remove placeholders or reinterpret encoded strings. Supports objects, arrays and scalar values when the extractor can decode them. Legacy normalization of YAML-like text followed by safe loading. The heuristics can change formatting, structure and scalar interpretation.

SAFE can handle supported headings, fences and prose around one object. It also handles supported combinations of missing and redundant separators where keys and values are already present. It may reject malformed text that an application could interpret using more context. Even two identical JSON documents in one response are rejected. Schema-aware repair remains planned. The SAFE v2 design contract includes future behavior beyond this beta.

Use parse_json(raw, policy="safe") for a JsonResult with value, repaired and strategy. Its default expected root is dict. For STRICT or TOLERANT, pass expected_type=object to allow any supported JSON root. Previously exported legacy extractors remain available. extract_json_new() returns JSON text, and extract_yaml_new() returns a Python value. dump_yaml() returns YAML text. YAML can return None for an empty document. STRICT JSON uses the Python decoder’s float semantics, including overflow in exponent notation. SAFE rejects that overflow. In TOLERANT mode, parse_json() tries the checked decoder before its repair fallback. The historical repair_json() default calls the extractor directly.

Handle failures and validate the result

from llm_output_repair import repair

def read_items(raw: str) -> list[int]:
    result = repair(raw)
    items = result.get("items")
    if not isinstance(items, list) or any(type(item) is not int for item in items):
        raise ValueError("Expected an array of integers")
    return items

try:
    items = read_items('{"items":[1,2,],}')
except ValueError:
    # Report a parsing or validation failure through your application.
    items = None

JSON parsing and policy refusals raise ValueError (including json.JSONDecodeError). Non-string arguments to repair() raise TypeError. YAML loading can raise yaml.YAMLError; tolerant YAML normalization can also raise ValueError. Deep inputs may hit Python's recursion limit. Validate field types, required fields and domain invariants after parsing. Errors can include input text, so handle their details as application data.

Opt-in diagnostics and replay

Importing the package and parsing normally create no diagnostic files or directories. The library performs no network calls, inference or background work. To capture a terminal failure explicitly, attach a CrashRecorder and choose a private directory:

from llm_output_repair import CrashRecorder, repair

recorder = CrashRecorder("./private-dumps")
try:
    repair('{"items":', recorder=recorder)
except ValueError:
    pass
.venv/bin/llm-repair replay ./private-dumps/CASE_ID.json
.venv/bin/llm-repair verify --corpus ./private-regressions --bucket fixed

Replay uses the saved operation and options locally. An expected terminal failure returns exit code 1 when replaying a raw dump. For a reviewed regression fixture, exit code 0 means the expectation matched. Use llm-repair promote --help to turn a dump into a fixture with an explicit expected value or error. Dumps can contain the original response. Keep them private. CrashLogger remains available for legacy diagnostic logs.

Beta support and limits

Supported and tested Python versions are 3.11, 3.12 and 3.13. The runtime requires PyYAML and Pydantic. The library has no Fetchgraph dependency. When migrating from a Git pin, install the new distribution in a fresh environment. A dependency declaration for the old distribution name must be updated separately.

The JSON and YAML repair and extraction entry points check a limit of 1,000,000 Python string characters before parsing. The malformed-object scan in JSON SAFE caps nesting at 128 levels. An object that decodes strictly can take a different path. The repeated candidate search in TOLERANT JSON caps the sum of inspected suffix lengths at 8,000,000 characters per search. These checks do not bound total CPU, memory, output size or depth across all decoder paths. For untrusted input, limit payloads, resulting sizes and alias expansion in the calling application. Use process-level limits when you need an enforceable execution budget.

See the changelog for compatibility changes and the repository for implementation, provenance and issue tracking.

License

This standalone library is licensed under MIT. The NOTICE records the provenance of the code extracted from Backplane.

Metadata

Release files for structured-output-repair 0.3.0b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for structured-output-repair 0.3.0b1
File Size Uploaded Provenance Actions
structured_output_repair-0.3.0b1.tar.gz 74.8 kB With provenance Details for structured_output_repair-0.3.0b1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for structured-output-repair 0.3.0b1
File Interpreter ABI Platform Actions
structured_output_repair-0.3.0b1-py3-none-any.whl Python 3 none any Details for structured_output_repair-0.3.0b1-py3-none-any.whl

Total release size: 133.9 kB

Release files / structured_output_repair-0.3.0b1.tar.gz

Download URL structured_output_repair-0.3.0b1.tar.gz
Size 74.8 kB
Tags Source
SHA-256 checksum
How to use checksums
06d98065459a7cc9cbb5d678df42da42cb3c23ecd689e28b8b5e9853453ba394
BLAKE2b-256 checksum
How to use checksums
40ac575c2e0f6b38ce4ae0cad72f24e83c41a6c8c4b05cf12b0fc6790dda7af2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / structured_output_repair-0.3.0b1-py3-none-any.whl

Download URL structured_output_repair-0.3.0b1-py3-none-any.whl
Size 59.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31b76c6cae6ee9756232e254a274b7e5daee868a22f529f171d232012d2d1db9
BLAKE2b-256 checksum
How to use checksums
6da39ccad1edb8d86e321d05c074c22bab558b8d148d74e3ea0f438b2ddf9d14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for structured-output-repair 0.3.0b1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for structured_output_repair-0.3.0b1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page