- Cost control — downgrade simple prompts to a cheaper model.
- 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 optionallyfailover_provider.
Conditions reference
Conditions are AND-ed together inside a rule. Use multiple rules with different priorities for OR semantics.
Actions reference
Smart failover
Whenfailover_provider is set on a matched rule and the primary upstream returns 5xx, PromptGuard:
- Logs the primary failure to
security_events.event_metadata.failover.primary_status. - Re-authenticates against the failover provider’s stored Provider Key.
- Issues exactly one retry. No exponential backoff, no recursion — if the failover also 5xx’s, the caller sees that error.
Match counters
Every rule that fires incrementsmatch_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
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.