Inspect every boundary.
Evaluate output before release.
Evaluate untrusted input before execution and the final answer before release. Block, warn, redact, or run your own Python policy, with every decision attached to the trace.
Read the guardrails docs- passed
prompt_injectionInput - redacted
piiInput - completed
agent executionRuntime - passed
moderationOutput - passed
system_prompt_leakageOutput
Enforce content policy at runtime boundaries
Instructions shape normal model behavior. Guardrails evaluate the content at the runtime boundary, before the agent sees an input and after it produces an output. The decision is recorded even when the request continues.
run_after_on_block: false is set.Cover the input and the answer
Use lightweight checks for common risks, model-backed classifiers when context matters, and custom Python when the policy belongs to your application.
| Rule | Direction | Modes | Purpose |
|---|---|---|---|
prompt_injection | Input | block · warn | Detect instruction-hijacking patterns |
pii | Input | block · warn · redact | Detect or replace configured PII entities |
moderation | Both | block · warn | Check configured safety categories |
topic_restriction | Input | block · warn | Classify requests against allowed or blocked topics |
regex | Both | block · warn | Apply application-specific text patterns |
pii_leakage | Output | block · warn · redact | Keep configured PII out of responses |
system_prompt_leakage | Output | block · warn | Compare output with the actual system prompt |
relevance | Output | block · warn | Classify whether the answer stayed relevant |
data_exfiltration | Output | block · warn | Flag suspicious external URLs and encoded payloads |
External provider options are available for prompt injection and moderation checks. Review every built-in guardrail and provider.
Start with four explicit checks
Start with prompt injection and PII on input, then moderation and system-prompt leakage on output. Tune from observed traces instead of guessing.
guardrails:
input:
- type: prompt_injection
mode: block
- type: pii
mode: redact
output:
- type: moderation
mode: block
- type: system_prompt_leakage
mode: block| Span | Status |
|---|---|
guardrail:prompt_injection | passed |
guardrail:pii | redacted |
guardrail:moderation | passed |
guardrail:system_prompt_leakage | passed |
blockReplace the unsafe response or skip agent execution for an input violation.
warnRecord the violation as a trace span and let processing continue.
redactReplace detected PII with typed placeholders on supported PII checks.
Write application-specific guardrails in Python
Use custom checks for tenant authorization, record shape, internal policy, and other application-owned validation.
from connic import GuardrailResult
import re
def check(content: str, context: dict) -> GuardrailResult:
"""Require a ticket ID before this agent runs."""
if not re.search(r"TICKET-\d{4,8}", content):
return GuardrailResult(
passed=False,
message="Include a valid ticket ID."
)
return GuardrailResult(passed=True)Required export
Export check(content, context) from a matching file under guardrails/.
Sync or async
Call your own policy or authorization service when a local rule is not enough.
Fail through the configured mode
An exception is logged and handled as a violation: warn continues; block stops processing.
Logs stay attached
Print, stderr, and standard logging appear under guardrail.<name> on the same run.
An input guardrail cannot depend on context values that before middleware has not created yet. Read the request from content, move that authorization check into middleware, or perform it in an output guardrail when middleware-enriched context is required.
Keep exploring
Approvals
Put a human before sensitive tool calls.
Observability
Inspect every evaluation in its run trace.
AI Governance
Turn runtime evidence into a governed record.
Testing
Exercise safety behavior before release.
Tools
Keep business actions narrow and explicit.
Managed Runtime
Enforce runtime limits around every run.