Skip to content

End-to-end Example#

This section provides practical walkthroughs from setup to verification. Each example is self-contained; complete the prerequisites for the workflow you need.

Example Purpose
Policies + Guardrails Validate PII guardrails on Chat Completion traffic

For connecting OpenCode or Cursor, see External Tools.

Policies + Guardrails#

This example validates PII protection for Chat Completion traffic and shows where to check evidence after sending test prompts. It is based on the Add Guardrail and Add Policy forms and focuses on how to confirm your configuration is actually enforced. The example assumes that the organization and provider are already configured.

1. Create guardrail

Field Example value
Name test-PII
Description This guardrail tests PII detection and redaction on input
Type PII detection and redaction
Stage Input
Threshold 0.7
Policy (action) Redact
PII fields CREDIT_CARD
Custom regexp patterns Optional (leave empty for this test)

Save the guardrail.

2. Create policy

Field Example value
Name chat-pii-check
Description Validate PII guardrail
Enabled On
Conditions request_type == "chat_completion"
Stage Input
Sampling rate 60%
Timeout 1500 ms
Request type Chat Completion
Pass on timeout Off (for strict validation)
Linked guardrails test-PII

Important: keep policy Stage aligned with the linked guardrail Stage for this test - guardrail is Input, keep policy stage Input.

Save the policy.

3. Run test prompts in AI Chat

Use an enabled provider and send prompts that include test credit-card-like values.

Example test prompt:

My test card is 4111 1111 1111 1111, summarize this message.

Run at least 3-5 requests so counters are easier to verify.

4. Verify that it works

Use the following checks:

  1. Response/content check — For Redact, sensitive entities should be masked before provider processing at the configured stage.

  2. Policy statistics check — Open the policy details and confirm that Requests evaluated and guardrail invocation metrics increase.

  3. Trace check — Open Traces and inspect a request. Confirm the policy match, guardrail execution, and result/action details.

Expected sequence

  1. Request enters AI Gateway with organization context.
  2. Policy matches traffic by request type/conditions.
  3. Linked guardrail executes at configured stage.
  4. PII is detected above threshold and action (Redact) is applied.
  5. Metrics and trace entries reflect the evaluation.

If you do not see matches

  • Confirm policy is Enabled.
  • Confirm guardrail is linked to that policy.
  • Confirm request type and conditions match your real traffic.
  • Confirm Sampling rate is 100% during testing.
  • Confirm policy/guardrail Stage alignment.