> For the complete documentation index, see [llms.txt](https://ai-security-docs.akto.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai-security-docs.akto.io/agentic-guardrails/concepts/session-guardrails.md).

# Session-Based Guardrails

## Overview

Session-based guardrails enable stateful, context-aware threat detection by maintaining session memory across multiple agent interactions. When your agent includes a session ID in the request header, Akto automatically analyzes prompts within the context of that entire session's history rather than evaluating each prompt in isolation.

This enables detection of threats that only become visible across multiple interactions, such as behavioral anomalies, gradual privilege escalation attempts, and incremental data exfiltration patterns.

## How Session-Based Guardrails Work

Akto's guardrail evaluation operates in two modes:

### Standard Guardrails (Stateless)

* Evaluate each prompt independently against configured policies
* No context from previous interactions
* Effective for detecting single-prompt threats (credentials in user input, prompt injection, etc.)
* Resets between requests

### Session-Based Guardrails (Stateful)

* Evaluate prompts within the context of the entire session's conversation history
* Maintain session memory across multiple interactions
* Correlate patterns across multiple prompts within a session
* Detect threats that emerge only when viewed across a timeline

<details>

<summary>Standard vs Session-Based Guardrails</summary>

| Aspect               | Standard Guardrails     | Session-Based Guardrails               |
| -------------------- | ----------------------- | -------------------------------------- |
| **Analysis Scope**   | Individual prompt       | Session conversation history           |
| **Context**          | Current prompt only     | Full interaction timeline              |
| **Memory**           | None                    | Session memory maintained              |
| **Threat Detection** | Single-prompt threats   | Multi-interaction patterns             |
| **Activation**       | Always active           | Via `X-Session-ID` header              |
| **Use Case**         | Quick, stateless checks | Behavioral analysis, anomaly detection |

</details>

## When to Use Session-Based Guardrails

Deploy session-based guardrails when you need to detect threats that span multiple interactions:

* **Behavioral Anomalies**: Detect unusual patterns in agent behavior across consecutive requests (e.g., privilege escalation attempts, role changes, access pattern drift)
* **Gradual Exfiltration**: Identify slow, incremental data leakage across multiple prompts (small amounts per request, cumulative risk)
* **Privilege Escalation**: Detect patterns of incrementally requesting higher permissions or access levels
* **Prompt Injection Chains**: Identify coordinated injection attempts across multiple turns
* **Session Compromise**: Detect indicators that a user session may have been compromised
* **Policy Violation Escalation**: Track progressive violations of guardrail policies within a session

## How to Enable Session-Based Guardrails

Enabling session-based guardrails is automatic and requires no configuration on Akto's side.

**Automatic Activation**: Session-based guardrails activate automatically when your agent includes a session ID in the request header. No additional configuration is required on Akto's side.

{% stepper %}
{% step %}

#### Generate a Session ID

Your agent generates a unique identifier for each user session
{% endstep %}

{% step %}

#### Include in Request Header

Attach the session ID to the `x-session-id` header when sending requests to Akto's guardrail service
{% endstep %}

{% step %}

#### Automatic Activation

Akto automatically detects the session ID and enables session-based threat detection
{% endstep %}
{% endstepper %}

### Example Request Header

```
x-session-id: session_abc123xyz789
```

### Integration Points

Session IDs can be passed via:

* **Guardrail Service API**: Include `x-Session-id` header in direct API calls
* **Proxy Integration**: Proxy layer forwards the session ID header to Akto
* **Other Integration Methods**: Any integration that preserves the `x-session-id` header

{% hint style="info" %}
**Need Help**

If you want session-based guardrails enabled for your agents, please contact the Akto support team for assistance with provisioning and setup.
{% endhint %}

## Related Concepts

* [Agent Guard](/agentic-guardrails/concepts/agent-guard.md) — Complete reference of all guardrail types and their capabilities
* [Guardrail Activity](/agentic-guardrails/concepts/guardrail-activity.md) — Monitoring and analyzing guardrail detections across sessions
* [Create Guardrail Policies](/agentic-guardrails/how-to/create-guardrail-policies.md) — Learn how to configure and deploy guardrail policies for your agents
