ProductionGuard¶
Added in v3.11.0
ProductionGuard is the batteries-included entry point for production deployments. It bundles calibrated scoring, human feedback loop, conformal confidence intervals, and agent tool-call verification into a single API.
Quick Start¶
from director_ai.guard import ProductionGuard
guard = ProductionGuard.from_profile("medical")
guard.load_facts({"dosage": "Max 400mg ibuprofen per dose."})
result = guard.check("What is the max dose?", "Take up to 800mg.")
print(result.approved, result.score)
With Calibration¶
Enable online calibration to get confidence intervals and adaptive thresholds:
guard.enable_calibration(alpha=0.1) # 90% confidence intervals
result = guard.check("What is the max dose?", "Max 400mg per dose.")
print(result.confidence_interval) # (0.72, 0.89)
print(result.calibrated_threshold) # adjusted from feedback
# Record human correction
guard.record_feedback(result, correct_label=True)
The calibrator absorbs feedback to update thresholds over time. The more feedback, the better the calibration.
Per-Claim Verification¶
For audit-grade evidence, use atomic claim verification against source text:
vr = guard.check_verified(
response="AES-256 at rest and TLS 1.3 in transit. Data retained for 90 days.",
source="AES-256 at rest and TLS 1.3 in transit. Data retained for 30 days.",
atomic=True,
)
for claim in vr.claims:
print(f"[{claim.verdict}] {claim.claim}")
for span in claim.evidence_spans:
print(f" source: {span.text[:60]} nli={span.nli_divergence:.3f}")
Agent Tool-Call Verification¶
Verify that an agent's function calls match a known manifest:
manifest = {
"get_dosage": {
"description": "Look up max dosage for a drug",
"parameters": {"drug": {"type": "string"}},
}
}
tool_result = guard.verify_tool(
"get_dosage", {"drug": "ibuprofen"}, '{"max_dose": "400mg"}',
manifest=manifest,
)
print(tool_result.approved, tool_result.issues)
API Reference¶
ProductionGuard¶
| Method | Description |
|---|---|
from_profile(name) |
Create from a named profile (fast, medical, finance, etc.) |
load_facts(facts) |
Load key-value facts into the knowledge base |
enable_calibration(alpha) |
Enable online calibration with conformal CIs |
check(prompt, response) |
Score a response, return GuardResult |
check_verified(response, source) |
Per-claim verification against source text |
record_feedback(result, label) |
Feed human correction into calibrator |
verify_tool(name, args, result, manifest) |
Verify agent tool call against manifest |
GuardResult¶
| Field | Type | Description |
|---|---|---|
approved |
bool |
Whether the response passed |
score |
float |
Coherence score [0, 1] |
coherence |
CoherenceScore |
Full scoring details |
confidence_interval |
tuple[float, float] | None |
Conformal CI (if calibration enabled) |
calibrated_threshold |
float | None |
Adjusted threshold (if calibration enabled) |