Skip to main content

llmparse

Parse the JSON your LLM meant to send.

LLMs promise JSON and deliver markdown fences, apologies, single quotes, trailing commas, Python literals — and, when the token budget runs out, JSON that stops mid-string. llmparse is a zero-dependency Python library that extracts the JSON from raw model output and repairs the damage, so json.loads stops being the most fragile line in your pipeline.

from llmparse import parse

parse('Sure! Here you go:\n```json\n{name: "ada", tags: ["x", "y",], ok: True}\n```')
# {'name': 'ada', 'tags': ['x', 'y'], 'ok': True}

parse('{"name": "ada", "tags": ["x", "y"')   # truncated stream
# {'name': 'ada', 'tags': ['x', 'y']}

Install

pip install llmparse-py     # once published to PyPI
pip install git+https://github.com/gptfei/llmparse

Python 3.9+. No third-party dependencies, ever.

What it fixes

Damage in LLM output Example
Markdown fences ```json ... ```
Prose around the JSON Here is the result: {...} hope it helps
Single-quoted strings {'a': 'b'}
Unquoted keys {name: "ada"}
Python / JS literals True, None, undefined, NaN
Comments {"a": 1} // note
Trailing commas {"a": [1, 2,]}
Truncation {"msg": "hello wor → closed and parsed

Brackets and comment markers inside string values are never touched.

API

  • parse(text, default=...) — return the recovered Python object. Raises LLMParseError when nothing is recoverable, unless default is given. loads is an alias.
  • extract(text) — return the first recoverable JSON substring, or None.
  • repair(text) — return repaired JSON text (for when you need the string, not the object).

Valid JSON is returned untouched: every repair rule is a no-op on input that already parses.

Contributing

The repair pipeline is a list of small, independent rules — adding one is the easiest meaningful contribution in open source right now:

  1. Find a way an LLM broke JSON that llmparse does not fix yet.
  2. Write the rule in src/llmparse/repair.py, register it in RULES.
  3. Add a test with the broken input.

See CONTRIBUTING.md and issues labelled good first issue.

中文简介

大模型说好返回 JSON,实际经常带 markdown 围栏、解释文字、单引号、 尾随逗号、Python 的 True/None,甚至输出到一半被截断。llmparse 是一个零依赖的 Python 库:从原始输出里提取 JSON、逐项修复这些损坏、 再解析成 Python 对象。合法 JSON 不会被改动。

License

MIT — see LICENSE.

Metadata

Release files for llmparse-py 0.1.1

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

Source distribution (sdist)

Source distribution for llmparse-py 0.1.1
File Size Uploaded Provenance Actions
llmparse_py-0.1.1.tar.gz 9.8 kB With provenance Details for llmparse_py-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llmparse-py 0.1.1
File Interpreter ABI Platform Actions
llmparse_py-0.1.1-py3-none-any.whl Python 3 none any Details for llmparse_py-0.1.1-py3-none-any.whl

Total release size: 18.3 kB

Release files / llmparse_py-0.1.1.tar.gz

Download URL llmparse_py-0.1.1.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8941e0715f411fe35f887f36b5d22550ad30598abdc17199c68f570a612b6e3b
BLAKE2b-256 checksum
How to use checksums
909cbcede6649eb4fd3c7966e2a932fe122ace634cb585b3e2dd6d1f7ecd3e52
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 5, 2026.

Transparency log

Release files / llmparse_py-0.1.1-py3-none-any.whl

Download URL llmparse_py-0.1.1-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb4c8c05eef40df4588a2028110b2d9bdb848b4c312b2d2661454d0254be429b
BLAKE2b-256 checksum
How to use checksums
54b9fcabd27fbc0230bdb100558fb1f88b5317006257a008b6a501b1e8e7c8e5
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 5, 2026.

Transparency log

Security for llmparse-py 0.1.1

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for llmparse_py-0.1.1.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 5, 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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

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