This package adheres to the FlossWare Engineering Standards.
Schema validation and retry behavior never activate automatically.
Users must explicitly wrap their LLM backend via StructuredOutputBackend
or apply the @structured_output decorator. No global state, no
monkey-patching, no implicit middleware.
StructuredOutputBackend(backend)-- explicit wrapper construction@structured_output(schema=...)-- explicit decorator application
The @structured_output decorator provides a composable, cross-cutting
concern (JSON schema validation with retries) that can be applied to any
async LLM call without modifying the function body.
@structured_output(schema={"type": "object", "required": ["name"]})
async def get_profile(messages, *, model=None, temperature=0.7, **kw):
return ChatResponse(content=await call_llm(messages))Zero required external dependencies. The package uses only the Python
standard library. The optional jsonschema package enables full JSON
Schema validation when installed; a built-in fallback validator handles
basic type and key checks otherwise.
- Modular: Each concern (types, protocol, structured output) lives in its own module.
- Composable:
StructuredOutputBackendwraps anyLLMBackend;@structured_outputwraps any async function. Both compose freely with other middleware. - Contracts over implementations: The
LLMBackendprotocol defines the contract viatyping.Protocol(structural subtyping). No base class inheritance required.
The package works with any agent runtime. It depends only on Python's
asyncio and imposes no framework, event loop, or orchestration
requirements. Any async callable returning ChatResponse is compatible.
Structured output is a capability layered on top of a transport-agnostic
LLMBackend protocol. The capability (schema validation, retry logic)
is fully independent of how the underlying LLM is accessed -- HTTP,
gRPC, in-process, or mock.