What it is
Prevention Config (displayed as Guards in the dashboard) lets you configure per-agent safety controls that run inside the LangSight SDK before each tool call is made. These controls are enforced at the call site — before the tool executes — not after the fact. Three guard types are available:Loop Detection
Detect and stop agents that call the same tool repeatedly with the same arguments, alternating between two calls, or retrying a failing call without progress.
Budget Controls
Cap the LLM + tool cost or wall-clock time of a session. Soft alerts before the hard limit; hard terminate when the limit is reached.
Circuit Breaker
Prevent an agent from hammering a failing MCP server. Trip the circuit after N failures, hold it open during a cooldown period, then allow limited traffic to test recovery.
Where to find it
Agents (/agents) → click any agent name → Guards tab
Loop Detection
Loop detection fires before each tool call by checking three patterns in the current session’s call history:| Pattern | Description |
|---|---|
| Repetition | Same tool called with identical arguments N times consecutively |
| Ping-pong | Alternating between two tool+argument pairs repeatedly (A→B→A→B→A…) |
| Retry without progress | Same tool failing with the same error N times in a row |
loop_detected health tag is applied to the session.
Float normalization: Before hashing tool arguments, the loop detector rounds all float values to 6 decimal places. This prevents LLMs from bypassing loop detection through micro-variations in numeric arguments — for example, {"price": 1.0} and {"price": 0.999999} hash identically. Integer, boolean, string, and null values are unchanged. The normalization applies recursively to nested objects and arrays.
Configuration fields
Turn loop detection on or off for this agent.
Number of consecutive repeat calls before the loop is detected and the action fires.
What to do when a loop is detected.
warn— log the event and fire a LangSight alert, but allow the call to proceed. The session is taggedloop_detected.terminate— block the call and terminate the session immediately. The session is taggedloop_detected.
Hard cap on total tool calls per session, regardless of repetition. When the session reaches this limit, the next call is blocked and the session is terminated. Leave unset for no limit.
The
warn action is the recommended starting point. Use it to measure how frequently loops occur before switching to terminate. Switching to terminate too early can break agents that use intentional retry logic.Budget Controls
Budget controls enforce cost and time limits per session. Limits are evaluated before each LLM call and tool call.Hard cost cap per session in USD. When the running total of LLM cost + tool cost reaches this value, the session is terminated and tagged
budget_exceeded. Leave unset for no limit.Warn when session cost reaches this value. A LangSight alert fires and the session is tagged
budget_warning, but execution continues. Must be less than max_cost_usd.Maximum session wall-clock time in seconds. When elapsed time exceeds this value, the next tool call is blocked and the session is terminated with
budget_exceeded.Unknown model fallback pricing
When a span’smodel_id is not found in the pricing_table passed to LangSightClient, the SDK uses a conservative fallback cost instead of treating the cost as $0:
| Rate | |
|---|---|
| Input tokens | $10.00 / 1M tokens |
| Output tokens | $30.00 / 1M tokens |
max_cost_usd limit would never fire if unknown model costs were treated as zero.
When the fallback is used, the SDK logs a warning:
pricing_table constructor parameter:
Circuit Breaker
The circuit breaker prevents an agent from repeatedly calling a failing MCP server. It operates in three states:| State | Behaviour |
|---|---|
| Closed | Normal operation — calls are allowed through |
| Open | Tripped after N failures — all calls to the server are blocked immediately |
| Half-open | After the cooldown period — a limited number of calls are allowed through to test whether the server has recovered |
Configuration fields
Turn the circuit breaker on or off for this agent.
Number of consecutive failures before the circuit trips to open state.
How long (in seconds) the circuit stays open before transitioning to half-open and allowing test traffic.
Maximum number of calls allowed in the half-open state to test whether the server has recovered.
The circuit breaker operates per-agent, per-server. An agent calling two servers has independent circuit breakers for each. One server failing does not trip the circuit for the other.
Config inheritance
Guards configuration uses a two-level inheritance model:Project default
A single configuration that applies to all agents in the project. Set it in Settings → Projects → Prevention Default. All agents without an agent-specific override inherit the project default. Changes to the project default take effect on the next agent run — there is no restart required.Agent override
When you save a config from the Guards tab for a specific agent, it creates an agent-level override. The Guards tab shows an “Agent-specific config” banner to indicate that this agent is no longer using the project default. Agent overrides take precedence over the project default in every field — there is no partial merge. If you set an agent override, the entire config (loop detection, budget, circuit breaker) comes from the override, not the project default.Reset to default
The “Reset to project default” button in the Guards tab deletes the agent-specific override. On the next agent run, the agent falls back to the project default. The historical guard events (loop detections, budget alerts) are not deleted — they remain in the session history.How to configure Guards
Select the Guards tab
The Guards tab shows the current configuration — either the project default (with a grey “Using project default” banner) or an agent-specific override (with an indigo “Agent-specific config” banner).
Configure the controls
Adjust the loop detection threshold, budget limits, and circuit breaker settings using the form fields. Each section can be enabled or disabled independently.
Data storage
Prevention configs are stored in theprevention_configs table in PostgreSQL:
agent_name = NULL is the project default. Rows with a non-null agent_name are agent overrides.
API reference
Get agent config
Save agent config
Reset to project default
Get project default
Save project default
Session health tags
Prevention Config actions produce the following session health tags, which appear in the Agents → Sessions tab and the session detail page:| Health tag | Cause |
|---|---|
loop_detected | Loop detection fired (warn or terminate action) |
budget_warning | Session cost reached soft_alert_threshold_usd |
budget_exceeded | Session cost or wall time reached the hard limit |
circuit_breaker_open | A call was blocked because the circuit is in the open state |
Related
- Agents — agent table, health scores, loop detection count column
- Session Health — full health tag reference
- Agent SLOs — reliability targets for agents
- Costs — session cost calculation and model pricing