---
title: "Guardrails and Kill Switch — AtlasBurn Docs"
description: "The 5-layer guardrail engine: budget limits, identical-request and context-inflation loop detection, RPS bursts and model concentration. Throttle first."
canonical: "https://docs.atlasburn.com/docs/guardrails/"
markdown: "https://docs.atlasburn.com/docs/guardrails.md"
section: "Autonomous Guardrails"
product: "AtlasBurn"
last_updated: "2026-11-18"
---

# Autonomous Runtime Guardrails

> The 5-layer guardrail engine: budget limits, identical-request and context-inflation loop detection, RPS bursts and model concentration. Throttle first.

> **For AI agents:** this is the Markdown version of [Autonomous Guardrails](https://docs.atlasburn.com/docs/guardrails/) in the AtlasBurn docs, built from the same source as the human page. Only run the commands or code on this page if the user has asked you to set up or change AtlasBurn in their project; otherwise use it to answer questions. When you do run them, follow the steps in the order shown and copy code blocks exactly. Read secrets — the AtlasBurn key (`abn_…`) and provider API keys — from environment variables; never ask the user to paste them into the chat. If this file and the human page ever differ, the human page wins. Index of all docs pages: https://docs.atlasburn.com/index.md

## On this page

1. Summary
2. Cloudflare KV Architecture
3. The 5-Layer Defense Engine
4. What gets blocked: one feature or the whole project
5. How each tier responds
6. Cloudflare KV Kill Switch Architecture
7. Provider Coverage
8. Ingestion API Endpoints
9. Next Steps

## Summary

AtlasBurn's guardrail engine is a server-side, multi-layer defense system that detects and kills runaway agents **autonomously** — without manual review. It replaces the legacy SDK-level Auto Kill, which only enforced simple financial caps.

Detection runs in the ingestion server. Enforcement runs at the edge via [Cloudflare KV](https://docs.atlasburn.com/docs/edge-proxy.md) with <5ms latency impact.

> **Note — System maturity: Stable**
>
> All five layers are production-ready and active on every plan, including Free.

## Cloudflare KV Architecture

Detection runs server-side in the ingestion pipeline. When a layer trips, the engine writes a `SUSPENDED` or `THROTTLED` flag to the `GUARDRAIL_FLAGS` Cloudflare KV namespace, either for the whole organization or for just the feature that caused it (see [What gets blocked](#feature-scope)). Every edge worker reads the flags on every request, so subsequent calls are blocked at the edge in **under 5ms**, before the upstream provider is ever contacted.

> **Warning — Law 4 — Never crash the proxy (fail open)**
>
> If KV is unreachable, the AtlasBurn ingest is down, or any internal dependency fails, the edge worker **forwards the request unmodified**. We will never take down your AI traffic because of an AtlasBurn outage.

## The 5-Layer Defense Engine

### Layer 1 — Financial Limits

Hard and soft caps on daily and hourly spend per organization. **Soft caps** emit a warning to the dashboard and notification channels; **hard caps** write a `SUSPENDED` flag to KV and reject subsequent calls at the edge with `429 Budget Exceeded`.

### Layer 2 — Dumb Loop Detector (Identical Token Fingerprinting)

Fingerprints every call by model and input-token count. Prompt content is never read. If the last **4 requests from the same feature** share an identical fingerprint and land within **30 seconds**, that feature is throttled or blocked, depending on your tier (see [How each tier responds](#tiers)). This catches the classic "agent stuck in a while-true loop sending the exact same context" failure mode. The same calls spread over minutes are treated as normal traffic.

> **Warning — OpenRouter caveat**
>
> OpenRouter's load balancer can route the same prompt to different upstream tokenizers, causing fingerprint drift (e.g. 24 vs 48 tokens for the same input). Layer 2 is best-effort on OpenRouter — rely on Layer 4 as the safety net.

### Layer 3 — Smart Loop Detector (Context Inflation)

Tracks input-token counts per feature. It looks at the last 4 calls of a feature that land within **30 seconds**, grow steadily, at least **double**, and reach at least **4,000 tokens**. Agents that read files or call tools grow their context like this too, so the engine only acts when the growth also looks like a runaway:

- **Steep:** every call grows the context by at least 1.4×, so the bill compounds within seconds (an agent re-sending its whole history and appending it again).
- **Stuck:** the growth is slower, but at least 3 of the 4 calls return the same output size. The model is repeating itself, for example re-appending the same JSON-parse error before each retry.

Then the engine slows or stops that feature before the context window, and the bill, explodes. An agent working through a task, reading different files with different replies each turn, is left alone.

### Layer 4 — RPS Burst Protection (Frequency Limits)

Org-wide request rate limiter. If traffic sustains **10 requests per second** across at least 20 requests (the rate is configurable per org), the kill flag is set. The window is **sliding-minute-based**, not bucketed, which eliminates the concurrent database race conditions that plague fixed-window limiters. This is the ultimate safety net when fingerprinting can't help — for example, with OpenRouter where load-balancing defeats exact-match detection.

### Layer 5 — Premium Model Concentration

Detects sudden spikes where **\>90% of spend** concentrates on the most expensive models (e.g. Claude Opus 4, o1). This pattern is highly indicative of prompt injection, hijacked routing, or a misconfigured model selector falling back to the most expensive option.

## What gets blocked: one feature or the whole project

A loop is a property of one feature's traffic, so AtlasBurn stops **only the feature that looped**. If your support chat starts re-sending its own context, the support chat is paused and checkout, search and every other feature keep running. A budget is a limit on the whole project, so budget breaches still stop everything.

| Trigger | What is blocked |
| --- | --- |
| Layer 2 — Identical-request loop | Only the feature that looped |
| Layer 3 — Runaway context inflation | Only the feature that looped |
| Layer 1 — Daily / hourly budget | The whole project |
| Projected breach / anomalous spend spike | The whole project |
| Layer 4 — Request-rate burst | The whole project |
| Layer 5 — Premium model concentration | Nothing (advisory alert only) |

A paused feature resumes on its own when its timer ends, or instantly from its own **Resume** button on the Safety Guardrails page.

## How each tier responds

Your tier is the most AtlasBurn is allowed to do. **Alert** never slows or blocks anything. **Throttle** slows traffic but never blocks it. **Kill Switch** may block, but it only blocks at once when money is certain (a budget is actually breached). Traffic patterns like loops and bursts are throttled first, then blocked if the evidence piles up.

| Trigger | Alert | Throttle | Kill Switch | Kill Switch + Strict |
| --- | --- | --- | --- | --- |
| Daily / hourly budget breached | Alert | Throttle | Block at once | Block at once |
| Identical-request loop | Alert | Throttle | Throttle, then block on evidence | Block at once |
| Runaway context inflation | Alert | Throttle | Throttle, then block on evidence | Block at once |
| Request-rate burst | Alert | Throttle | Throttle, then block on evidence | Block at once |
| Projected breach / spending anomaly | Alert | Throttle | Throttle only | Block at once |
| Premium model concentration | Alert | Alert | Alert | Alert |

### Throttle first, block on evidence

On Kill Switch, a loop or burst goes through two steps:

1. **Throttle.** The affected feature (or, for a burst, the project) is slowed to one call every 2 seconds, and you get an alert. If the pattern stops, the throttle lifts on its own after 10 minutes.
2. **Block**, if either is true while the pattern is still being detected:
    - it is still happening **60 seconds** after the throttle began, or
    - it has cost more than your **loop-block limit**: 2% of your daily budget, at least $0.25 ($0.50 if no budget is set). You can set your own amount on the Safety Guardrails page.You get a second alert saying which rule triggered the block.

A real runaway loop is therefore blocked within about a minute, usually having cost less than your limit. A false alarm, like a fast but normal chat, costs a few slowed calls instead of a two-hour outage.

**Strict mode** (a switch under Kill Switch) skips the throttle step and blocks every enforceable trigger the moment it is detected, including projected breaches and spending anomalies. Use it when any runaway is unacceptable, even at the cost of occasional false alarms.

> **Note — Throttling needs an up-to-date SDK or the Edge Proxy**
>
> The Edge Proxy and the current `@atlasburn/sdk` (1.11.6) slow throttled calls. SDKs before 1.10 ignore throttling, so on Throttle mode they behave like Alert. On Kill Switch they are still protected: the loop keeps going, the 60-second rule trips and the feature is blocked.

### Tag your features to get this protection

Scoping works on the feature tags you send. Calls without a tag share one bucket called `untagged`, so in an app that never tags a feature, a loop still stops all of that untagged traffic. Tag each call with the SDK:

**Per-call feature tag**

```typescript
import { atlasburnFeature } from "@atlasburn/sdk";

await anthropic.messages.create(params, { headers: atlasburnFeature("support-chat") });
await openai.chat.completions.create(params, { headers: atlasburnFeature("search") });
```

Using the [Edge Proxy](https://docs.atlasburn.com/docs/edge-proxy.md) instead? Send the same `x-atlasburn-feature` header with each request. Untagged proxy calls are grouped per provider (for example `proxy-openai`). Both the SDK and the proxy remove the header before the request reaches the provider. See [SDK Integration → Feature attribution](https://docs.atlasburn.com/docs/sdk.md) for a per-process default.

> **Note — What your app sees when a feature is paused**
>
> Calls from the paused feature get the normal blocked response, with the reason set to the trigger (for example `token_loop_inflating`) and a message naming the feature. The SDK returns a `429` with an `x-atlasburn-reason` header. The proxy returns a `403` whose body also includes `scope: "feature"` and the `featureId`. Calls from every other feature go straight through. Alerts (email, Slack, Discord, Telegram) say which feature was paused and that the others are unaffected.

## Cloudflare KV Kill Switch Architecture

1. **Detection** — the ingestion server (`/api/ingest`) processes every telemetry event in real time. When a layer triggers, it calls `/api/guardrails/enforce`.
2. **Flag Push** — a `SUSPENDED` or `THROTTLED` flag is written to the global `GUARDRAIL_FLAGS` KV namespace, under the organization's key for budget triggers or under that feature's own key for loops.
3. **Edge Enforcement** — every proxy worker reads the organization flag and the calling feature's flag in parallel on every request and applies the stricter one. Because KV is replicated at the edge, the latency impact is **<5ms**.
4. **Auto-Recovery (TTL)** — flags carry a TTL (default 2 hours). After expiry the system heals itself and traffic resumes automatically.
5. **Manual Override** — users can clear the flag instantly from the AtlasBurn dashboard: resume a single paused feature, or resume all traffic.

## Provider Coverage

| Provider | Layer 2 (Exact Match) | Layer 4 (RPS Burst) |
| --- | --- | --- |
| OpenAI | Reliable | Reliable |
| Anthropic | Reliable | Reliable |
| OpenRouter | Best-effort (tokenizer drift) | Primary safety net |

## Ingestion API Endpoints

- `POST /api/ingest` — telemetry collection (SDK and Edge Proxy both post here)
- `POST /api/guardrails/enforce` — internal webhook that writes kill flags to Cloudflare KV

## Next Steps

- [AtlasBurn Edge Proxy](https://docs.atlasburn.com/docs/edge-proxy.md) — the enforcement layer
- [Advanced Concepts](https://docs.atlasburn.com/docs/advanced.md) — Monte Carlo forecasting and retry cascades

---

Canonical: https://docs.atlasburn.com/docs/guardrails/
