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.

Table 1: OptScale AI end-to-end examples
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. For field-level procedures, see Guardrails — Add a guardrail and Policies — Add a policy. The example assumes that the organization and provider are already configured.

1. Create guardrail

Table 2: Example guardrail configuration
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
Action Redact
PII fields CREDIT_CARD
Custom regexp patterns Optional (leave empty for this test)

Save the guardrail.

2. Create policy

Table 3: Example policy configuration
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. The guardrail is Input, so set the policy Stage to Input.

Save the policy.

3. Run test prompts in 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 to 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. Usage Statistics check — Open the policy detail page and review Usage Statistics. Confirm that Requests evaluated and guardrail invocation metrics increase after test traffic.

Expected sequence

  1. Request enters the AI Gateway with organization context.
  2. Policy matches traffic by request type and conditions.
  3. Linked guardrail executes at the configured stage.
  4. PII is detected above the threshold and the Redact action is applied.
  5. Policy usage statistics 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.