Policies Overview
LangGuard's policy engine enables automated governance and compliance for AI operations. Define rules, detect violations, and ensure your AI systems meet organizational standards.
What Are Policies?
Policies are rules that evaluate AI agent traces to detect:
- Security risks - PII exposure, credential leaks, unapproved tools, identity violations
- Compliance violations - Model approval, cross-boundary access, audit requirements
- Cost overruns - Budget thresholds, per-trace cost limits, token limits
- Operational health - Latency thresholds, error rates, metadata completeness
How It Works
LangGuard uses Open Policy Agent (OPA) with policies written in Rego:
Trace Ingested → Policy Evaluation → Violations Logged → Webhooks Triggered
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ New Trace │────▶│ OPA Server │────▶│ Violations │
│ Arrives │ │ (Rego Eval) │ │ Recorded │
└─────────────────┘ └─────────────────┘ └─────────────────┘
OPA Engine Health
The Policies page displays an OPA engine health status indicator showing whether the policy evaluation engine is running correctly. A healthy status means policies are being evaluated in real time as traces arrive. If the engine is unhealthy, policy evaluations are queued and processed once the engine recovers.
Policy Evaluation Pipeline
When a new trace is ingested:
- Trace received — LangGuard receives the trace from a connected integration
- Policy selection — All enabled policies are identified
- OPA evaluation — Each enabled policy's Rego code is evaluated against the trace data
- Violation recording — Any violations are recorded with severity, evidence, and the originating policy
- Notifications — Configured webhooks are triggered for violations
Policy Components
Policy Definition
Each policy includes:
| Component | Description |
|---|---|
| Name | Unique identifier |
| Description | What the policy detects |
| Category | Security & Access, Models & Compliance, Budget & Operations, Audit |
| Severity | Critical, High, Medium, Low |
| Rego Code | The evaluation logic |
| Mode | Enforce, Permissive, or Disabled |
| Enabled | Active or disabled |
Example Policy
package langguard.pii_detection
import rego.v1
# Emit a violation for each PII match when the detect_pii tag is present
violation contains result if {
has_pii_tag
pii := object.get(input, "pii_detection", {})
pii.found == true
some match in pii.matches
result := {
"type": "pii_detected",
"pii_type": match.type,
"location": match.location,
"message": sprintf("PII detected (%s) in %s", [match.type, match.location]),
}
}
Built-in Policies
LangGuard includes pre-configured policies across all categories:
| Policy | Category | Severity | Default |
|---|---|---|---|
| Credential Surface Discovery | Security & Access | Critical | Enabled |
| PII Detection | Security & Access | Critical | Enabled |
| Non-Human Identity Violation | Security & Access | High | Disabled |
| Unapproved Tool Use | Security & Access | High | Enabled |
| Approved Model Version | Models & Compliance | High | Disabled |
| Latency/Health Threshold | Models & Compliance | Medium | Disabled |
| Cross-Boundary Access | Models & Compliance | Critical | Enabled |
| Budget Overrun Detection | Budget & Operations | High | Disabled |
| Mandatory Trace Logging | Audit | Low | Enabled |
| Metadata Tagging Requirements | Audit | Low | Enabled |
Documentation
- Built-in Policies - Details on all pre-configured policies
- AI Policy Authoring - Generate policies from plain-language intent
- Creating Policies - Write custom policies with Rego
- Data Sources - Let a policy read a list or a JSON document from one of your systems
- Budgets & Cost Control - Track cost and enforce spend budgets
- Policy Violations - Understanding and managing violations
Policy Modes
Each policy can operate in one of three modes:
| Mode | Behavior |
|---|---|
| Enforce | Violations are logged and the action is blocked. Use for critical policies that must prevent harmful behavior. |
| Permissive | Violations are logged but the action is allowed to proceed. Use for monitoring and tuning new policies before enforcing them. |
| Disabled | The policy is not evaluated. No violations are recorded. |
Choosing a Mode
- Start with Permissive — When deploying a new policy, use Permissive mode first to observe what it catches without impacting operations
- Promote to Enforce — Once you're confident the policy is correctly calibrated, switch to Enforce mode
- Use Disabled sparingly — Only disable policies you no longer need; consider Permissive mode instead for policies you want to pause temporarily
When a Policy Cannot Be Evaluated
A policy can fail to evaluate. For example, the policy engine returns an error for the Rego code, or the package name does not match the policy. This is a policy evaluation error. The policy engine is still reachable. LangGuard does not read the failure as "no violations".
The mode of the failed policy decides what LangGuard does:
| Mode | Result |
|---|---|
| Enforce | The call fails closed. LangGuard blocks gateway and chat calls. Arbiter hooks return ASK. The applied rule is policy_evaluation_error, and the reason names the policy. |
| Permissive | The call is not blocked. LangGuard records the error as a notify entry with the policy ID and the error text. |
When LangGuard records an error and does not block, it also writes an error log entry.
The decision audit record has a policy_evaluation_errors attribute that lists the
failed policies. Other policies decide the call as usual.
- Shadow mode. On the MCP gateway, Shadow mode (the default) never blocks a call. It records the error of an Enforce policy and does not block the call. If LangGuard cannot read the mode, it blocks the call. Arbiter hooks and chat traffic ignore Shadow mode.
- Policy engine unreachable. This is a different failure. LangGuard cannot reach the policy engine. The call fails closed on every path, except the MCP gateway in Shadow mode, which records the failure and does not block the call.
- Traces. When one policy cannot be evaluated for a trace, LangGuard does not record the trace as evaluated for that run. The trace keeps the state it had. LangGuard does not delete the existing open violations of that policy for the trace. Violations from other policies are still stored. This is the same for every mode.
To find a policy that cannot be evaluated, look for could not be evaluated in the
block and notify entries of the response. You can also look for the
policy_evaluation_errors attribute in the decision audit record.
Best Practices
1. Start with Built-in Policies
Enable built-in policies first to establish baseline governance:
- Enable "Credential Surface Discovery" and "PII Detection" for security
- Enable "Cross-Boundary Access" to enforce environment isolation
- Enable "Budget Overrun Detection" to control costs
2. Tune Severity Levels
Adjust severity based on your risk tolerance:
- Critical: Must be addressed immediately
- High: Review same day
- Medium: Review weekly
- Low: Informational only
3. Review Violations Regularly
Establish a violation review process:
- Daily: Check critical violations
- Weekly: Review all violations
- Monthly: Analyze trends, adjust policies
4. Create Custom Policies
After understanding built-in policies, create custom ones for:
- Company-specific compliance requirements
- Application-specific guardrails
- Industry regulations
Next Steps
- Built-in Policies - Explore available policies
- Creating Policies - Write your own
- Workflow Governance - Gate asset lifecycle promotions with policies
- Troubleshooting - Get help with common issues