StructGuard
Reliable, provider-agnostic structured outputs for production LLM applications.
StructGuard makes sure every LLM response conforms to a schema you define —
Pydantic, dataclass, TypedDict, or raw JSON Schema — before it reaches
your application code. It handles prompting, JSON repair, validation, and
intelligent retries in one call, across OpenAI, Anthropic, Gemini, Groq, and
Ollama.
Install
pip install structguard # core only
pip install structguard[openai] # + OpenAI SDK
pip install structguard[anthropic] # + Anthropic SDK
pip install structguard[all] # every provider SDK
Quick start
from pydantic import BaseModel
from openai import OpenAI
from structguard import generate
class Incident(BaseModel):
summary: str
priority: str
confidence: float
client = OpenAI()
incident = generate(
llm=client,
prompt="Summarize this incident: Database connection pool exhausted, causing 500s.",
schema=Incident,
)
print(incident.summary, incident.priority, incident.confidence)
With a full report
result = generate(llm=client, prompt=prompt, schema=Incident, return_report=True)
print(result.data)
print(result.report) # ✓ Success | provider=OpenAI model=gpt-4o-mini retries=0 ...
Error handling
from structguard import RetryLimitExceeded, SchemaValidationError
try:
incident = generate(llm=client, prompt=prompt, schema=Incident, max_retries=2)
except RetryLimitExceeded as e:
print(f"Gave up after {e.attempts} attempts: {e.last_error}")
Supported schema types
pydantic.BaseModel- stdlib
@dataclass TypedDict- raw JSON Schema
dict
Supported providers
OpenAI · Anthropic · Google Gemini · Groq · Ollama
Development
git clone https://github.com/sujanrupu/structguard
cd structguard
pip install -e ".[dev]"
pytest
License
MIT
Metadata
Release files for structguard 0.1.4
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 | |
|---|---|---|---|---|
| structguard-0.1.4.tar.gz | 17.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| structguard-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.0 kB
Release files / structguard-0.1.4.tar.gz
| Download URL | structguard-0.1.4.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1ca1675c4127ba3edcaf7011d0cc86ebc1830c9f4595d7a1d1d98e85ef695f0
|
|
BLAKE2b-256 checksum How to use checksums |
9bf9936c53c28e4dbf775603b75f5fcd11ede77faa5df43cdf3d6c1b1b372be5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Release files / structguard-0.1.4-py3-none-any.whl
| Download URL | structguard-0.1.4-py3-none-any.whl |
|---|---|
| Size | 18.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
829e7d718c0e487318fcbdd2a94384590cc492e7abc0b03de2864d6558aeb12a
|
|
BLAKE2b-256 checksum How to use checksums |
7292ca26e40118aa3780ba01e560853ab09977502558b82941322134bd99f4a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Security for structguard 0.1.4
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.