Metadata-Version: 2.4
Name: structguard
Version: 0.1.4
Summary: Reliable, provider-agnostic structured outputs for production LLM applications.
Project-URL: Homepage, https://github.com/sujanrupu/structguard
Project-URL: Repository, https://github.com/sujanrupu/structguard
Author-email: Sujan Ghosh <rupubally@gmail.com>
License: MIT
License-File: LICENSE
Keywords: anthropic,gemini,json,llm,openai,pydantic,structured-output,validation
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Requires-Dist: pydantic>=2.0
Provides-Extra: all
Requires-Dist: anthropic>=0.30; extra == 'all'
Requires-Dist: google-generativeai>=0.5; extra == 'all'
Requires-Dist: groq>=0.5; extra == 'all'
Requires-Dist: openai>=1.0; extra == 'all'
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.30; extra == 'anthropic'
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Provides-Extra: gemini
Requires-Dist: google-generativeai>=0.5; extra == 'gemini'
Provides-Extra: groq
Requires-Dist: groq>=0.5; extra == 'groq'
Provides-Extra: openai
Requires-Dist: openai>=1.0; extra == 'openai'
Description-Content-Type: text/markdown

# 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

```bash
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

```python
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

```python
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

```python
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

```bash
git clone https://github.com/sujanrupu/structguard
cd structguard
pip install -e ".[dev]"
pytest
```

## License

MIT
