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.
Try it live in your browser
— paste broken JSON and watch it get repaired. The demo runs the real
llmparse package in your browser via Pyodide; nothing is sent to a
server.
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
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'} |
| Curly quotes | “a”: “b” → "a": "b" (content inside strings untouched) |
| Unquoted keys | {name: "ada"} |
| Python / JS literals | True, None, undefined, NaN |
| Comments | {"a": 1} // note, # note |
| Missing commas | {"a": 1 "b": 2} |
| Trailing commas | {"a": [1, 2,]} |
| Unescaped quotes / newlines in strings | "Ada Lo"velace", raw newline in a value |
| Truncation | {"msg": "hello wor → closed and parsed |
Prose around the JSON is handled by the extractor (extract() in
core.py, built on scanner.py), which finds the first top-level
JSON value in the text; the other ten rows map one-to-one to the ten
rules in RULES (repair.py).
Brackets and comment markers inside string values are never touched.
A nested fragment is never returned in place of the top-level value:
if the top-level JSON cannot be recovered, parse() raises
LLMParseError instead of handing you a piece of the document.
API
parse(text, *, default=...)— return the recovered Python object. RaisesLLMParseErrorwhen nothing is recoverable, unlessdefaultis given.loadsis an alias.extract(text)— return the first recoverable JSON substring, orNone.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.
Why not json_repair?
json_repair is the established library in this space (5,143 stars on
GitHub, ~49 million PyPI downloads a month) and the right default for
most people. It offers schema-guided repair, streaming support, a CLI,
a live demo and a docs site — more features than llmparse will ever
have.
llmparse exists for the narrower case where you want the smallest possible dependency and the strictest guarantees:
- Zero dependencies, ever — one small package, Python 3.9+.
- Strings are sacred: brackets and comment markers inside string values are never touched, and valid JSON is returned untouched — every repair rule is a no-op on input that already parses.
- Three-layer API:
parse(object),extract(first recoverable JSON substring),repair(repaired JSON text) — pick the layer you need instead of one all-or-nothing call.
What llmparse does not do: no schema-guided repair, no streaming parser, no CLI, no docs site. If you need any of those, use json_repair.
Correctness
- 54 tests (
tests/test_parse.py,tests/test_rules.py), run on every push by CI (Python 3.9, 3.11, 3.12 on Linux, macOS and Windows). - Every repair rule is a no-op on valid JSON — the suite asserts that
directly (
test_rules_do_not_change_valid_json). - Benchmarked against json_repair, partialjson and pure-json on 194
hand-built damaged cases (seed
20261129): llmparse 100% success, 78.4% exact, 80.9% prefix — vs json_repair 100% / 77.3% / 79.4%. Full write-up, method, limitations and raw per-case results: the benchmark article andbenchmark/in this repo. The numbers above are for 0.1.2; the round-2 fixes shipped in 0.1.2.
Contributing
The repair pipeline is a list of small, independent rules — adding one is the easiest meaningful contribution in open source right now:
- Find a way an LLM broke JSON that llmparse does not fix yet.
- Write the rule in
src/llmparse/repair.py, register it inRULES. - 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 不会被改动。
See also
- devsnap — snapshot and diff your development environment; end "works on my machine" debugging.
License
MIT — see LICENSE.
Metadata
Release files for llmparse-py 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llmparse_py-0.1.2.tar.gz | 16.8 kB | With provenance | Details for llmparse_py-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llmparse_py-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for llmparse_py-0.1.2-py3-none-any.whl |
Total release size: 30.3 kB
Release files / llmparse_py-0.1.2.tar.gz
| Download URL | llmparse_py-0.1.2.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ae6a39ba85d8a7ab0af507dee2c46f1fb82e038acb8670522504244fe7bcc801
|
|
BLAKE2b-256 checksum How to use checksums |
ead7f672d77d2213a3e503732d0308f1aaec89c747a665a3a5b76dd913fa4071
|
| 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 logRelease files / llmparse_py-0.1.2-py3-none-any.whl
| Download URL | llmparse_py-0.1.2-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
78cfac24e8477602fa3b02aada0ac7d30e37b5d0448bbafc013065d4829328fe
|
|
BLAKE2b-256 checksum How to use checksums |
4ebf19ddb90a71d45eacb4c8df4db7233c1a824242c0c9a8d9c42c117824c45f
|
| 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 logSecurity for llmparse-py 0.1.2
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.
Attestation for llmparse_py-0.1.2.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 logA 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.