Reliable, structured, production-safe LLM outputs with schema validation and auto-repair
Project description
PromptGuard
Never parse LLM output again.
LLMs are probabilistic. Software is deterministic.
PromptGuard bridges the gap.
PromptGuard is a production-grade reliability layer that turns Large Language Models into safe, structured, testable software components.
If your application depends on LLM outputs — agents, workflows, background jobs, voice systems, document parsing — then PromptGuard prevents the failures that eventually break every LLM app in production.
Why PromptGuard Exists
Every LLM developer eventually runs into this:
json.loads(llm_output) # crashes in prod
Because LLMs:
- return invalid JSON
- hallucinate fields
- change output formats
- break silently after model updates
- fail one out of every N requests
These failures cause:
- background job crashes
- broken agents
- corrupted pipelines
- silent data loss
- 2am production incidents
PromptGuard eliminates this entire class of problems.
What PromptGuard Guarantees
- Schema-valid outputs — always
- Automatic repair when models misbehave
- Deterministic structured data
- Prompt regression testing
- Provider-agnostic execution
No regex. No fragile parsing. No silent failures.
Why PromptGuard Over Alternatives?
| Feature | PromptGuard | Instructor | Outlines |
|---|---|---|---|
| Auto repair loop | Yes (N retries) | 1 retry | No |
| Multi-provider | 4 built-in | OpenAI-centric | Multiple |
| Prompt versioning | Built-in | No | No |
| Regression testing | Built-in | No | No |
| Schema types | 4 (Pydantic, TypedDict, dataclass, JSON) | Pydantic | Limited |
| CLI tooling | Yes | No | No |
PromptGuard is a reliability layer, not just a parser. Versioning + testing + repair in one package.
Installation
pip install llm-promptguard
# With provider-specific dependencies
pip install llm-promptguard[openai]
pip install llm-promptguard[anthropic]
pip install llm-promptguard[google]
pip install llm-promptguard[all]
Quick Start
from promptguard import llm_call
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
result = llm_call(
model="gpt-4o",
prompt="John is 30 years old",
schema=Person
)
print(result.data)
# Person(name='John', age=30)
If the model returns invalid output, PromptGuard automatically:
- detects the schema violation
- explains the error
- re-prompts the model
- repairs the output
- returns guaranteed valid data
Real-World Examples
Resume & Document Parsing
class Resume(BaseModel):
name: str
skills: list[str]
years_experience: int
resume = llm_call(
prompt=resume_text,
model="gpt-4o",
schema=Resume
)
- No missing fields
- No malformed JSON
- No broken pipelines
Email Triage Automation
class EmailIntent(BaseModel):
intent: str
urgency: int
requires_reply: bool
intent = llm_call(
prompt=email_body,
model="gpt-4o",
schema=EmailIntent
)
Safe to run in background workers. Safe to store in databases. Safe to trigger workflows.
AI Agents (Tool Calling)
class ToolArgs(BaseModel):
action: str
resource_id: str
args = llm_call(
prompt=agent_prompt,
model="gpt-4o",
schema=ToolArgs
)
run_tool(**args.data.model_dump())
PromptGuard prevents agents from:
- hallucinating arguments
- calling tools incorrectly
- freezing execution chains
Voice Agents & Call Automation
Speech → LLM → Action
If structure breaks, the call fails.
PromptGuard ensures voice systems always receive valid commands.
Background Jobs & Queues
@worker.task
async def process_document(text):
result = await allm_call(
prompt=text,
model="gpt-4o",
schema=Extraction
)
save(result.data)
No retries. No poison messages. No corrupted jobs.
LangChain Integration
PromptGuard works seamlessly with LangChain.
from langchain.tools import Tool
from promptguard import llm_call
from pydantic import BaseModel
class SearchArgs(BaseModel):
query: str
search_tool = Tool(
name="search",
func=lambda q: search_api(q),
description="Search the web"
)
args = llm_call(
prompt="Search for Tesla earnings",
model="gpt-4o",
schema=SearchArgs
)
search_tool.run(args.data.query)
PromptGuard becomes the type-safe boundary between agents and tools.
Prompt Regression Testing
promptguard test
- detects prompt drift
- catches model behavior changes
- prevents silent regressions
LLM prompts finally become testable.
The Demo
class Order(BaseModel):
product: str
quantity: int
price: float
order = llm_call(
prompt="Buy two iPhones for $999 each",
model="gpt-4o",
schema=Order
)
print(order.data)
# Order(product='iPhone', quantity=2, price=999.0)
No parsing. No retries. No crashes.
Just software-safe AI.
Mental Model
Without PromptGuard:
LLM → text → hope → bugs
With PromptGuard:
LLM → contract → software
When You Should Use PromptGuard
If your application:
- runs LLMs in production
- executes workflows or agents
- parses model output
- stores results in databases
- depends on structure
Then PromptGuard is not optional.
CLI Commands
promptguard init # Initialize in a project
promptguard run prompt.yaml # Run a prompt from YAML
promptguard test # Run regression tests
promptguard history # Show version history
promptguard diff <hash> # Compare versions
promptguard stats # Show statistics
Supported Providers
| Provider | Model Examples |
|---|---|
| OpenAI | gpt-4o, gpt-4o-mini, gpt-4-turbo |
| Anthropic | claude-3-opus, claude-3-sonnet, claude-3-haiku |
| gemini-1.5-pro, gemini-1.5-flash | |
| Local | Ollama, LM Studio, vLLM (OpenAI-compatible) |
Testing with real LLM Calls
- export OPENAI_API_KEY=sk-...
- ./scripts/test_all.sh
Documentation
Full docs at metanoia-oss.github.io/promptguard.
License
Apache 2.0
PromptGuard — because production AI must be dependable.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_promptguard-0.1.1.tar.gz.
File metadata
- Download URL: llm_promptguard-0.1.1.tar.gz
- Upload date:
- Size: 61.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e0052e87a75af9c6ddb9483af35527fc1d1b68d22c5fe6852c0f85f64affc81
|
|
| MD5 |
abffa291fd0793eae60cc4de1a86ab18
|
|
| BLAKE2b-256 |
ecff939134aa4745ebdccc685bfbbce2ad8087e9da44a180dc9f4a09168fa178
|
Provenance
The following attestation bundles were made for llm_promptguard-0.1.1.tar.gz:
Publisher:
publish.yml on metanoia-oss/promptguard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_promptguard-0.1.1.tar.gz -
Subject digest:
6e0052e87a75af9c6ddb9483af35527fc1d1b68d22c5fe6852c0f85f64affc81 - Sigstore transparency entry: 867624701
- Sigstore integration time:
-
Permalink:
metanoia-oss/promptguard@69e0dd112ad5d68afd321e509c9afa59c3779ff2 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/metanoia-oss
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@69e0dd112ad5d68afd321e509c9afa59c3779ff2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file llm_promptguard-0.1.1-py3-none-any.whl.
File metadata
- Download URL: llm_promptguard-0.1.1-py3-none-any.whl
- Upload date:
- Size: 53.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67b6be1b0c06719cb33dc378cf133dca54ab56bd21cc09db5f8250feb6ddbb38
|
|
| MD5 |
00b8aad7e9bf815abf1a336daa99d7e2
|
|
| BLAKE2b-256 |
0c0d6a49382e53f8261bd89a9e073a8ca87df471df7c51cc9499a70cb9c626ec
|
Provenance
The following attestation bundles were made for llm_promptguard-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on metanoia-oss/promptguard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_promptguard-0.1.1-py3-none-any.whl -
Subject digest:
67b6be1b0c06719cb33dc378cf133dca54ab56bd21cc09db5f8250feb6ddbb38 - Sigstore transparency entry: 867624738
- Sigstore integration time:
-
Permalink:
metanoia-oss/promptguard@69e0dd112ad5d68afd321e509c9afa59c3779ff2 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/metanoia-oss
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@69e0dd112ad5d68afd321e509c9afa59c3779ff2 -
Trigger Event:
release
-
Statement type: