Metadata-Version: 2.4
Name: llmparse-py
Version: 0.1.1
Summary: Parse the JSON your LLM meant to send — zero-dependency extraction and repair for raw LLM output.
Author: gptfei
License: MIT
Project-URL: Homepage, https://github.com/gptfei/llmparse
Project-URL: Repository, https://github.com/gptfei/llmparse
Project-URL: Issues, https://github.com/gptfei/llmparse/issues
Keywords: llm,json,parser,repair,openai,chatgpt,claude,structured-output
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# 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.

```python
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

```bash
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](CONTRIBUTING.md) and issues labelled
`good first issue`.

## 中文简介

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

## License

MIT — see [LICENSE](LICENSE).
