Skip to main content
Routing rules are priority-ordered rewrites that PromptGuard applies between auth and policy evaluation. Each rule has a condition (when it fires) and an action (what it changes). The first matching rule wins. The two big use cases:
  1. Cost control — downgrade simple prompts to a cheaper model.
  2. Vendor pinning — force a specific tenant onto a specific provider, e.g. for compliance or data-residency reasons.

Anatomy

  • priority — lower numbers fire first. Use 100, 200, 300, … so you can wedge new rules between old ones without renumbering.
  • condition — JSON object describing what to match. See the conditions reference below.
  • action — JSON object describing the rewrite. May set provider, model, and optionally failover_provider.

Conditions reference

Conditions are AND-ed together inside a rule. Use multiple rules with different priorities for OR semantics.

Actions reference

Smart failover

When failover_provider is set on a matched rule and the primary upstream returns 5xx, PromptGuard:
  1. Logs the primary failure to security_events.event_metadata.failover.primary_status.
  2. Re-authenticates against the failover provider’s stored Provider Key.
  3. Issues exactly one retry. No exponential backoff, no recursion — if the failover also 5xx’s, the caller sees that error.
Non-5xx responses (rate limits, validation errors, timeouts) are surfaced as-is. The gateway does not switch vendors for a 429, because a 429 from the primary usually means your account is being rate limited, and switching providers without telling the caller is a great way to silently drop traffic.

Match counters

Every rule that fires increments match_count and updates last_matched_at. The dashboard surfaces these so you can spot dead rules (created six months ago, never matched) and aggressive ones (matching 90% of traffic — probably too broad).

Worked example

A gpt-4 request from an internal tenant gets rewritten to Claude Sonnet 4.5 (priority 50 fires first). A request without that header but containing “summarise the following” goes to gpt-5-nano. Any other GPT request stays on OpenAI but falls back to Anthropic on a 5xx.