Skip to main content
Guardrails scan agent inputs and outputs to enforce safety and policy boundaries. Idun Engine provides 15 built-in guardrail types powered by Guardrails AI, applied at the input position, output position, or both.

How guardrails work

Guardrails run at two positions in the agent request lifecycle:
  • Input guardrails validate user messages before the agent processes them. If any input guardrail fails, the request is blocked immediately and the agent never sees the message.
  • Output guardrails validate agent responses before returning them to the user. They run after agent processing completes. Output guardrails add latency to the response time.
You can configure multiple guardrails at each position. All guardrails at a given position are checked, and any single failure blocks the request or response.

Configuration

Add guardrails in the guardrails section of your config.yaml. Each guardrail has a config_id that identifies the type and parameters specific to that type.
config.yaml
Infrastructure fields (api_key, guard_url, reject_message) are populated automatically. For YAML-based configs the api_key is read from the GUARDRAILS_API_KEY environment variable. You only need to specify the config_id and guard-specific parameters.
Guardrails need a Guardrails AI API key. Either set it once in the admin form on your first guardrail (the standalone persists and re-hydrates it on boot), or export it as GUARDRAILS_API_KEY in your environment. Get a key from Guardrails AI.

Available guardrail types

All 15 guardrail types and their key parameters:

Adding guardrails through config file

For first-boot seeding (or engine-only mode), add guardrails directly to your config.yaml:
config.yaml
Each guardrail entry supports an optional reject_message field to customize the error message returned when the guardrail triggers:

Testing guardrails

After configuring guardrails, verify they work as expected by sending test requests through the API.
When a guardrail blocks a request, the response includes the guardrail field identifying which guard triggered and a detail message explaining why.

Best practices

  • Layer multiple guardrails at the input position for defense in depth. Combine ban lists with PII detection and jailbreak prevention.
  • Use output guardrails sparingly since they add latency. Reserve them for critical checks like hallucination detection or gibberish filtering.
  • Set thresholds conservatively at first (higher values = stricter), then lower them if you see too many false positives.
  • Test with realistic inputs before production. Send messages that should trigger each guardrail and verify legitimate content passes through.

Next steps

Guardrails reference

All 15 guardrail types and their configuration fields.

Observability

Monitor guardrail activity in traces.

Deployment

Deploy your agent to Cloud Run, a VM, or your laptop.
Last modified on May 26, 2026