raif-format (Python)
Pure-Python implementation of RAIF — a token-efficient, repair-tolerant layer for the JSON language models produce: structured outputs, strict objects, JSON mode, tool arguments. Stdlib only, no runtime dependencies, fully typed (PEP 561). Tool calls are one use case, not the point.
This package mirrors the canonical TypeScript reference byte-for-byte; parity is pinned by a shared conformance corpus.
- Spec & monorepo: https://github.com/skrrt-sh/raif-standard
- JavaScript/TypeScript package:
raif-formaton npm
Install
pip install raif-format # or: uv add raif-format
Installs the raif-format distribution; the import package is raif.
Usage
from raif import encode, decode, decode_lenient, fix, validate, parse_schema
# JSON object -> canonical RAIF (byte-identical to the TS encoder)
encode({"to": "a@b.com", "subject": "hi"})
# 'subject=hi\nto=a@b.com'
# Generation profile (what models are trained to emit)
encode({"items": [{"id": 1}, {"id": 2}]}, {"profile": "generation"})
# RAIF -> JSON (with repair reporting)
decode("a=1\nb=hi")
# {'ok': True, 'value': {'a': 1, 'b': 'hi'}, 'repairs': []}
# Per-leaf recovery — never raises, surfaces truncation
decode_lenient("<raif>\ncity=Oslo\nlat")
# {'value': {'city': 'Oslo'}, 'errors': [...], 'repairs': [...], 'truncated': True}
# Canonicalize (decode -> re-encode); idempotent
fix("```\na=1\n```")
# {'ok': True, 'canonical': 'a=1', 'repairs': [...]}
# Read-only canonicality check
validate("a=1")
# {'ok': True}
# Optional schema-typed decode
schema = parse_schema("priority:n\nnote:s?")
decode("priority=2\nnote=hi", schema)
API
| Function | Returns |
|---|---|
encode(obj, opts=None) |
str (canonical RAIF) |
decode(text, schema=None) |
{"ok", "value"|"error", "repairs"} |
decode_lenient(text, schema=None) |
{"value", "errors", "repairs", "truncated"} |
fix(text, schema=None) |
{"ok", "canonical"|"error", "repairs"} |
validate(text, schema=None) |
{"ok"} or {"ok": False, "errors"} |
parse_schema(decl) |
RaifSchema |
opts is {"profile": "canonical" | "generation", "markers": bool}.
The RAIF ecosystem
raif-format is the Python codec (installs as raif-format, imports as raif);
everything else builds on the same format.
- Spec, ADRs & conformance corpus:
raif-standard - JavaScript/TypeScript package, same name:
raif-formaton npm - Models that emit RAIF natively — LoRA fine-tunes that make small/local models output RAIF instead of JSON. Decode their output with this package:
decode(model_output)["value"].skrrt-sh/raif-llama-3.2-3b-lora— clears the v0.5 gate (100% parse / 95% fidelity)skrrt-sh/raif-qwen3-4b-lora— agent-grade, runs on ~14 GB VRAMskrrt-sh/raif-qwen2.5-0.5b-lora— a 6×-smaller-base study- Training & eval recipe:
raif-lora
License
Apache-2.0
Metadata
Release files for raif-format 0.6.0
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 |
|---|---|---|---|---|
| raif_format-0.6.0.tar.gz | 51.9 kB | With provenance | Details for raif_format-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| raif_format-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for raif_format-0.6.0-py3-none-any.whl |
Total release size: 83.2 kB
Release files / raif_format-0.6.0.tar.gz
| Download URL | raif_format-0.6.0.tar.gz |
|---|---|
| Size | 51.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77c651efdef893b5a939dda05e50e3b664b445bd670fa1df6a87241fdccec7c1
|
|
BLAKE2b-256 checksum How to use checksums |
af35781e2bb53b8e753cccaf7b268ae179a97c0ad92a32582f090bb016aa10fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 Jun 21, 2026.
Transparency logRelease files / raif_format-0.6.0-py3-none-any.whl
| Download URL | raif_format-0.6.0-py3-none-any.whl |
|---|---|
| Size | 31.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7682601cd80c29c93c3ecb7e67b9f217d99ba62b370035bbe27ffb180703732
|
|
BLAKE2b-256 checksum How to use checksums |
a499ef14a967e4937d9a16f60d655ffe2e57aacb44593bbccc9e80ace4462918
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 Jun 21, 2026.
Transparency logSecurity for raif-format 0.6.0
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 raif_format-0.6.0.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 Jun 21, 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.