arcanada-output-guard
Validate, repair, and retry LLM structured output (JSON / YAML / TOML / Python literal) — battle-tested 15-strategy repair chain with two-pass orchestrator. Python sibling of @arcanada/output-guard with shared golden fixtures and byte-equal parity gate.
Install
pip install arcanada-output-guard
# or
uv add arcanada-output-guard
# or
poetry add arcanada-output-guard
Requires Python ≥ 3.11. Runtime deps: pyyaml, tomli-w, pydantic, jsonschema, json-repair.
Quick start
from output_guard import repair
# Functional API — format-only repair, no schema
result = repair('{"name": "Alice", "age": 30,}', "json")
print(result.data) # {'name': 'Alice', 'age': 30}
print(result.repaired) # True
print(result.pass_) # 'A'
print(result.strategies_applied) # ['fix-commas']
Stateful API with pydantic schema
from pydantic import BaseModel
from output_guard import OutputGuard
class User(BaseModel):
name: str
age: int
guard = OutputGuard(format="json", schema=User)
result = guard.repair('```json\n{"name": "Bob", "age": 25}\n```')
print(result.data) # User(name='Bob', age=25)
print(result.pass_) # 'A' or 'B'
Output format support
- JSON — strict + relaxed parsing with common error recovery (trailing commas, unquoted keys, single→double quote, true/false casing, fenced blocks).
- YAML — structural repair for indentation + missing keys.
- TOML — fixing malformed tables and value assignments.
- Python literal —
dict/listliterals via safeast.literal_eval. - Auto-detect — pass
format="auto"to infer from content.
RepairResult semantics
@dataclass(frozen=True, slots=True)
class RepairResult:
repaired: bool # False when raw was already valid
raw: str # original input as supplied
pass_: Literal["A", "B"] # "A" = combined-apply; "B" = isolating fallback
data: Any = None # parsed + (optionally) schema-validated payload
strategies_applied: list[str] = [] # ordered list of repair strategies invoked
MAX_RETRIES exhaustion signals via ParseError raise, not via a pass_ value.
Async wrapper for LLM calls
import asyncio
from pydantic import BaseModel
from output_guard import guarded_generate, GuardedGenerateOptions
class Answer(BaseModel):
result: int
async def my_llm(prompt: str, history=None) -> str:
# call your LLM client here (OpenAI / Anthropic / OpenRouter / MC / etc.)
return '{"result": 42}'
async def main():
out = await guarded_generate(GuardedGenerateOptions(
generate=my_llm,
prompt='Return JSON {"result": <integer>}',
schema=Answer,
fmt="json",
max_retries=3,
))
print(out.data) # Answer(result=42)
print(out.pass_) # 'A' | 'B'
print(out.strategies_applied)
asyncio.run(main())
Error handling
from output_guard import (
ParseError,
SchemaValidationError,
RepairError,
GuardedGenerationError,
)
try:
result = guard.repair(bad_input)
except SchemaValidationError:
... # input parsed but doesn't satisfy schema
except ParseError:
... # MAX_RETRIES exhausted — all strategies failed
except RepairError:
... # a repair strategy itself raised
except GuardedGenerationError:
... # guarded_generate gave up after max_retries LLM round-trips
Schema adapters
from output_guard import pydantic_adapter, jsonschema_adapter
from pydantic import BaseModel
class User(BaseModel):
name: str
age: int
# pydantic v2
adapter = pydantic_adapter(User)
# JSON Schema (dict)
adapter = jsonschema_adapter({
"type": "object",
"properties": {"name": {"type": "string"}, "age": {"type": "integer"}},
"required": ["name", "age"],
})
Batch API
from output_guard import repair_batch
results = repair_batch(
['{"a": 1,}', '{"b": 2,}', '{"c": 3,}'],
fmt="json",
)
# returns list[RepairResult]; per-item failure surfaces as RepairResult with repaired=False
Documentation
- Source: https://github.com/Arcanada-one/output-guard/tree/main/packages/python
- Design (two-pass orchestrator, strategy ordering): see repository docs
- TypeScript sibling: https://www.npmjs.com/package/@arcanada/output-guard
License
MIT — see LICENSE.
Жизнь одного человека имеет значение / One human life matters
Metadata
Release files for arcanada-output-guard 0.1.3
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 |
|---|---|---|---|---|
| arcanada_output_guard-0.1.3.tar.gz | 49.3 kB | With provenance | Details for arcanada_output_guard-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| arcanada_output_guard-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for arcanada_output_guard-0.1.3-py3-none-any.whl |
Total release size: 75.4 kB
Release files / arcanada_output_guard-0.1.3.tar.gz
| Download URL | arcanada_output_guard-0.1.3.tar.gz |
|---|---|
| Size | 49.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
849bbe5cf3724b2058fb51daa62a966ac8d0dec46e7e498ca7c0e4c68d2f099c
|
|
BLAKE2b-256 checksum How to use checksums |
181f1271707c1e72911203bdf2aa99bdbda5851d1dfd6ac55a05d398336b1f6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 13, 2026.
Transparency logRelease files / arcanada_output_guard-0.1.3-py3-none-any.whl
| Download URL | arcanada_output_guard-0.1.3-py3-none-any.whl |
|---|---|
| Size | 26.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c073a2da5f6d5a9bb62426b9a26764a9b834d8316b5c33805a2561853f9926d1
|
|
BLAKE2b-256 checksum How to use checksums |
f2f7d30aef18137b16ca02c29f2ad68e6decbacf5d34c6395ec0e9241d2aee0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 13, 2026.
Transparency logSecurity for arcanada-output-guard 0.1.3
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 arcanada_output_guard-0.1.3.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 May 13, 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.