Behavioral validation for LLM outputs in production workflows.
Project description
Gateframe
Behavioral validation for LLM outputs. Not schema validation - tools like Instructor and Pydantic AI already handle that. gateframe validates whether an LLM output behaves correctly given the context it was generated in, stays within decision boundaries, and fails in ways your system can recover from.
from pydantic import BaseModel
from gateframe.core.contract import ValidationContract
from gateframe.core.failure import FailureMode
from gateframe.rules.structural import StructuralRule
class TriageOutput(BaseModel):
severity: str
recommendation: str
confidence: float
contract = ValidationContract(
name="triage_check",
rules=[
StructuralRule(schema=TriageOutput),
],
)
result = contract.validate({
"severity": "high",
"recommendation": "Escalate to on-call engineer",
"confidence": 0.92,
})
assert result.passed
When validation fails, you get structured failure records - not just a boolean:
result = contract.validate({"severity": "high"})
assert not result.passed
for failure in result.failures:
print(failure.message)
# structural:TriageOutput failed: recommendation: Field required; confidence: Field required.
Failure modes
gateframe distinguishes four failure modes instead of binary pass/fail:
HARD_FAIL - Stop execution, escalate. The output is wrong in a way that cannot be auto-recovered.
# Missing required fields in a medical triage output
StructuralRule(schema=TriageOutput, failure_mode=FailureMode.HARD_FAIL)
SOFT_FAIL - Flag the output and continue with degraded confidence. Something is off but not critical.
# Output has all fields but confidence is below threshold
StructuralRule(schema=TriageOutput, failure_mode=FailureMode.SOFT_FAIL)
RETRY - Re-prompt with failure context. The output is fixable by trying again.
# Malformed JSON that might parse on a second attempt
StructuralRule(schema=TriageOutput, failure_mode=FailureMode.RETRY)
SILENT_FAIL - The most dangerous kind. Output looks valid but violates semantic or boundary rules. gateframe makes these visible instead of letting them pass through.
When to use gateframe
Use it when:
- You need to validate LLM outputs beyond schema checks - behavioral contracts, decision boundaries, cross-step propagation
- You need structured failure records for debugging production incidents
- You want to distinguish between "retry this", "flag this", and "stop everything"
Don't use it when:
- You only need schema extraction from LLM outputs (use Instructor or Pydantic AI)
- You need offline model evaluation or benchmarking (use DeepEval or RAGAS)
- You need content safety filtering (use a dedicated guardrails tool)
Installation
pip install gateframe
For development:
git clone https://github.com/practicalmind-ai/gateframe.git
cd gateframe
pip install -e ".[dev]"
Quickstart
from pydantic import BaseModel
from gateframe.core.contract import ValidationContract
from gateframe.rules.structural import StructuralRule
from gateframe.audit.log import AuditLog
# Define your expected output schema
class AgentResponse(BaseModel):
action: str
reasoning: str
# Create a contract with rules
contract = ValidationContract(
name="agent_response_check",
rules=[StructuralRule(schema=AgentResponse)],
)
# Validate LLM output
result = contract.validate({
"action": "send_email",
"reasoning": "User requested a follow-up email to the client.",
})
# Log the validation event
audit = AuditLog()
audit.record(result)
Running tests
pip install -e ".[dev]"
pytest -q
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 gateframe-0.1.0.tar.gz.
File metadata
- Download URL: gateframe-0.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4aec88dca9ffc8802bcb03a9195021e5206bed142957d546e182f64e7ee95efc
|
|
| MD5 |
dcb600261ce1ff07dcf89608698d44bf
|
|
| BLAKE2b-256 |
ddff2334432a63301899355e428a1f8f416e5a746eb7565f6b8c409257f9224e
|
File details
Details for the file gateframe-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gateframe-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5c14a00a031873c4dea1f1cd3f87a1c351295bf11a2a8e90c0615a1b29c8aca
|
|
| MD5 |
8d539b4142d927c9b5696813d406513a
|
|
| BLAKE2b-256 |
649ab4138839433c709ee43dc9f57474aab1cd5c134d6af25afbb561b7ce18a2
|