docs / reference

Policy Rules

Configure per-project LLM call governance rules from the dashboard — no redeploy needed.

Policy rules let you control LLM call behavior at the gateway level. Rules are configured in the noburn dashboard and evaluated before each call — without touching your application code or triggering a deployment.

How rules work

Rules are evaluated top-to-bottom. The first rule that matches the current call wins. If no rule matches, the call proceeds normally.

Each rule has two parts:

  • When — a condition that must be true for the rule to apply
  • Then — what to do when the condition matches

Available actions

ActionWhat happens
blockCall is rejected. No tokens sent. Returns blocked: true.
force_smallcheck() returns forcedModelTier: 'small'. Your code switches to your cheaper model.
force_bigcheck() returns forcedModelTier: 'big'. Your code switches to your more capable model.
allowCall is explicitly allowed (use to override an earlier block rule)

Condition keys

KeyTypeDescriptionExample
utilization0.0 – 1.0Fraction of monthly budget already spent>= 0.8
modelstringThe model passed to check()gpt-4o
customanyAny key you pass in context when calling the SDKplan == free

noburn only computes utilization and model. Every other key is matched exactly against the context you pass to check(). Rules created with the older domain or complexity options keep working as custom keys: they match only if your app passes that key in context.

noburn does not inspect prompts, so it has no built-in complexity or topic score. If you compute one yourself, pass it in context (for example { "complexity": "0.3" }) and match on it like any custom key.

Configuring rules in the dashboard

Go to your project → Policy rules → Add rule.

The form guides you through each condition key with appropriate inputs — no manual typing of model names or operator syntax.

Rules take effect immediately after saving. The SDK fetches the latest rules when it initializes and refreshes them periodically.

Example rules

Block GPT-4o when budget is 80% spent:

WhenThen
utilization >= 0.8→Force cheap model

Block all calls to GPT-4o for free-plan users:

WhenThen
model gpt-4o→Block call

Then add a second rule to allow GPT-4o-mini for the same users:

WhenThen
plan free→Force cheap model

Give paying users the more capable model:

WhenThen
plan pro→Force powerful model

Route a task type you tag yourself to a powerful model (pass context: { task: 'creative' }):

WhenThen
task creative→Force powerful model

For "Free gets 20 generations a day", use usage quotas rather than a rule — a quota counts usage per user and tells you when to suggest an upgrade.

Passing custom context

To match on custom keys like plan, pass a context dict when calling the SDK:

result = guard.check(
    model="gpt-4o",
    estimated_tokens_in=1000,
    estimated_tokens_out=300,
    end_user_id="user_abc123",
    context={"plan": "free"},   # matched against policy rules
)
const result = await guard.check({
  model: 'gpt-4o',
  estimatedTokensIn: 1000,
  estimatedTokensOut: 300,
  endUserId: 'user_abc123',
  context: { plan: 'free' },   // matched against policy rules
});

The context object can contain any key-value pairs. Keys must match exactly what you've configured in the dashboard.

SDK fetch endpoint

If you're calling the REST API directly, fetch your project's rules from:

GET /api/v1/policy?project_id=<your-project-id>
Authorization: Bearer sk-nb-xxxxxxxxxxxxxxxx

Response:

{
  "rules": [
    { "when": { "utilization": ">= 0.8" }, "then": "force_small" },
    { "when": { "model": "gpt-4o" },       "then": "block" }
  ]
}

Only enabled rules are returned, ordered by position.

Rule evaluation order

Rules are evaluated in the order they appear in the dashboard (position 1, 2, 3…). You can reorder them by updating positions — first match wins, so order matters.

A common pattern: put the most specific rules first (e.g. model == gpt-4o AND plan == enterprise → allow) before broader rules (e.g. model == gpt-4o → block).

On this page