Skip to main content

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:

  1. Trace received — LangGuard receives the trace from a connected integration
  2. Policy selection — All enabled policies are identified
  3. OPA evaluation — Each enabled policy's Rego code is evaluated against the trace data
  4. Violation recording — Any violations are recorded with severity, evidence, and the originating policy
  5. Notifications — Configured webhooks are triggered for violations

Policy Components​

Policy Definition​

Each policy includes:

ComponentDescription
NameUnique identifier
DescriptionWhat the policy detects
CategorySecurity & Access, Models & Compliance, Budget & Operations, Audit
SeverityCritical, High, Medium, Low
Rego CodeThe evaluation logic
ModeEnforce, Permissive, or Disabled
EnabledActive 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:

PolicyCategorySeverityDefault
Credential Surface DiscoverySecurity & AccessCriticalEnabled
PII DetectionSecurity & AccessCriticalEnabled
Non-Human Identity ViolationSecurity & AccessHighDisabled
Unapproved Tool UseSecurity & AccessHighEnabled
Approved Model VersionModels & ComplianceHighDisabled
Latency/Health ThresholdModels & ComplianceMediumDisabled
Cross-Boundary AccessModels & ComplianceCriticalEnabled
Budget Overrun DetectionBudget & OperationsHighDisabled
Mandatory Trace LoggingAuditLowEnabled
Metadata Tagging RequirementsAuditLowEnabled

Documentation​

Policy Modes​

Each policy can operate in one of three modes:

ModeBehavior
EnforceViolations are logged and the action is blocked. Use for critical policies that must prevent harmful behavior.
PermissiveViolations are logged but the action is allowed to proceed. Use for monitoring and tuning new policies before enforcing them.
DisabledThe 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:

ModeResult
EnforceThe 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.
PermissiveThe 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​