Provider agnostic
One interface across OpenAI, Anthropic, Mistral, Ollama and any HTTP endpoint. Swap providers without touching parsing logic.
Production-grade reliability middleware for structured LLM outputs. Extract JSON, validate with Pydantic, repair malformed responses and return typed Python objects.
llm-reliability-engine
Prompt
Raw Response
JSON Extraction
JSON Parsing
Pydantic Validation
Deterministic Repair
LLM Repair
StructuredResult
Raw LLM Response
malformedSure! Here is the user:
```json
{
"name": "Ada Lovelace",
"email": "ada@analytical.dev",
"age": "36",
"roles": ["admin", "engineer",],
}
```Successfully validated after 2 attempts
StructuredResult<User> returned
repaired: trailing comma removed · age coerced to int
Features
One interface across OpenAI, Anthropic, Mistral, Ollama and any HTTP endpoint. Swap providers without touching parsing logic.
Deterministic fixes for fenced blocks, trailing commas, single quotes and truncated objects before a retry is ever spent.
Responses are coerced into your Pydantic models, so downstream code receives typed Python objects instead of dictionaries.
Attempt-level metadata, latency tracking, structured logging and bounded retries with exponential backoff built in.
Quick start
from pydantic import BaseModel
from llm_reliability_engine import ReliableClient
class User(BaseModel):
name: str
email: str
age: int
roles: list[str]
client = ReliableClient(provider="openai:gpt-4o-mini", max_attempts=3)
result = client.structured(
prompt="Extract the user profile from this email thread.",
schema=User,
)
print(result.value.name)
print(result.attempts)
print(result.parse_method)Playground
Prompt
Raw Response
unparseableStructured Output
validated