aiwarden-sdk 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ .mypy_cache/
7
+ build/
8
+ dist/
9
+ .coverage
10
+ .venv/
11
+ venv/
12
+ .env
13
+ .env.local
14
+ *.swp
15
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 aiwarden
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.5
2
+ Name: aiwarden-sdk
3
+ Version: 0.1.0
4
+ Summary: Official Python client for aiwarden — AI governance, threat detection, and agent oversight
5
+ Project-URL: Homepage, https://platform.aiwarden.ai
6
+ Project-URL: Documentation, https://platform.aiwarden.ai/documentation
7
+ Author: aiwarden
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: agents,ai,governance,guardrails,llm,prompt-injection,security
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Security
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.9
24
+ Requires-Dist: httpx>=0.27
25
+ Requires-Dist: pydantic>=2.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
28
+ Requires-Dist: pytest>=8; extra == 'dev'
29
+ Requires-Dist: respx>=0.21; extra == 'dev'
30
+ Requires-Dist: ruff<0.7,>=0.6; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # aiwarden — Python SDK
34
+
35
+ Official Python client for [aiwarden](https://platform.aiwarden.ai) — AI governance, threat detection, and agent oversight.
36
+
37
+ > Status: alpha. API surface may change before `1.0.0`.
38
+
39
+ ## Install
40
+
41
+ ```bash
42
+ pip install aiwarden-sdk
43
+ ```
44
+
45
+ ## Quickstart
46
+
47
+ ```python
48
+ from aiwarden import Aiwarden
49
+
50
+ client = Aiwarden(api_key="awd_live_...")
51
+
52
+ # Per-request analysis (regex + AI threat detection, attachments supported)
53
+ verdict = client.analyze(prompt="Ignore all previous instructions")
54
+ print(verdict.action) # "block"
55
+
56
+ # Full agent governance (policies, rate limits, MCP, approvals, lineage)
57
+ result = client.agents.execute(
58
+ agent_id="my-foundry-agent",
59
+ action_type="llm_call",
60
+ prompt="Summarize this customer ticket",
61
+ user={"email": "alice@acme.com"},
62
+ )
63
+ if result.action == "block":
64
+ raise RuntimeError(result.reason)
65
+ ```
66
+
67
+ ## Agentic Endpoint: aiwarden inside your agent
68
+
69
+ Install the package in the agent's environment and it governs the whole agent:
70
+ every model call and every tool it is about to run is checked with aiwarden
71
+ first, and the verdict is applied (allow, block, hold for approval).
72
+
73
+ ```bash
74
+ pip install aiwarden-sdk
75
+ export AIWARDEN_INSTALL_CODE=aep_...
76
+ export AIWARDEN_AGENT_ID=billing-agent # optional; defaults to <script>@<host>
77
+ ```
78
+
79
+ The install code (created in the portal, Integrations → Agentic Endpoint)
80
+ expires and has a limit of uses. On its first start the agent swaps it for a
81
+ credential of its own, kept in `~/.aiwarden` (owner-only), so your account key
82
+ never reaches the machine the agent runs on. An agent without a disk has
83
+ nowhere to keep it: start that one with `AIWARDEN_API_KEY=<your agents key>`
84
+ instead.
85
+
86
+ One line at the top of the agent:
87
+
88
+ ```python
89
+ import aiwarden.endpoint as endpoint
90
+ endpoint.install()
91
+ ```
92
+
93
+ Or no code change at all:
94
+
95
+ ```bash
96
+ aiwarden-run python my_agent.py
97
+ ```
98
+
99
+ What it attaches to (verified against the real libraries in `tests/test_endpoint.py`
100
+ and `tests/test_endpoint_frameworks.py`):
101
+
102
+ | Where | What is checked |
103
+ |---|---|
104
+ | OpenAI client (`chat.completions`, `responses`) | the person's message, the tools the model asks for, and tool results before the model reads them |
105
+ | Anthropic client (`messages`) | same |
106
+ | LangChain / LangGraph tools | the moment a tool runs, and its output |
107
+ | OpenAI Agents SDK (`openai-agents`) function tools | the moment a tool runs, and its output (`Runner.run` and `Runner.run_streamed`, Responses and Chat Completions) |
108
+ | CrewAI tools | the moment a tool runs, and its output (native tool calls and ReAct, any model provider) |
109
+ | Your own functions | `@endpoint.guarded` |
110
+
111
+ Because it hooks the model client itself, it also covers agents written with
112
+ plain API calls and any framework that calls OpenAI or Anthropic through their
113
+ SDKs.
114
+
115
+ A blocked tool never runs. By default the model is told with a neutral message
116
+ and the agent goes on (`AIWARDEN_ON_BLOCK=replace`); with `raise`,
117
+ `aiwarden.endpoint.AiwardenBlocked` is raised. `endpoint.set_user(email)` tells
118
+ aiwarden on whose behalf the agent is acting. `endpoint.status()` shows what is
119
+ attached and how many actions were checked, blocked, or let through without a
120
+ verdict.
121
+
122
+ Fail-open: if aiwarden cannot be reached, the agent keeps working and the
123
+ action is counted as `ungoverned`.
124
+
125
+ Streaming is governed too (`create(stream=True)` in both clients): text flows
126
+ as it arrives and only the events that ask for a tool are held until aiwarden
127
+ answers.
128
+
129
+ What the model answers is sent back to aiwarden off the agent's path (text of
130
+ the last answer of a turn, real tokens, time of the call), so the agent's cost
131
+ and its answers show up in aiwarden. When the policy's containment can change
132
+ an answer (retry once, hold or close the session), the package waits for
133
+ aiwarden's verdict on it; otherwise nothing waits. A short-lived agent should
134
+ call `endpoint.flush()` before exiting.
135
+
136
+ Known limits: the `.stream()` helpers of both SDKs (`chat.completions.stream`,
137
+ `responses.stream`, `messages.stream`) are checked on the request side only
138
+ (`create(stream=True)` is fully governed in the three APIs); a blocked tool
139
+ call in the non-streamed Responses API always raises (not inside the OpenAI
140
+ Agents SDK, where the tool is decided when it runs); answers asked for through
141
+ `with_raw_response` / `with_streaming_response` are checked on the request side
142
+ only (CrewAI's OpenAI provider does this: its tools are governed by the CrewAI
143
+ hook, but that model's answers and tokens are not reported); MCP clients do not
144
+ have their own hook yet. In the OpenAI Agents SDK, handoffs are checked at the
145
+ model only, and hosted, shell, computer and custom tools are not checked. In
146
+ CrewAI, the model call is governed only for the providers that use the OpenAI
147
+ or Anthropic SDK; `on_block=raise` cannot leave a CrewAI hook, so a denied tool
148
+ is blocked and the model told; and a crew that clears CrewAI's tool hooks
149
+ removes aiwarden's too.
150
+
151
+ ## What this SDK covers (v0.1)
152
+
153
+ - `client.analyze()` — `POST /analyze` (per-request, supports text + attachments).
154
+ - `client.ask()` — `POST /ask` (full proxy LLM flow with detection + intel logging).
155
+ - `client.agents.execute()` — `POST /api/agent/v1/execute` (full agent governance pipeline).
156
+ - `client.agents.register()` — `POST /api/agent/v1/register`.
157
+ - `client.agents.list_tools()` — `GET /api/agent/v1/tools`.
158
+ - `client.agents.status()` — `GET /api/agent/v1/status`.
159
+
160
+ ## Fail mode
161
+
162
+ By default the SDK is **fail-open**: if aiwarden times out or errors, your agent continues without governance (a `WARN` is logged). Switch to strict for regulated workloads:
163
+
164
+ ```python
165
+ client = Aiwarden(api_key="awd_live_...", fail_mode="closed", timeout=2.0)
166
+ ```
167
+
168
+ ### Latency budget
169
+
170
+ `timeout` is **per attempt**. On a transient failure (network, 5xx, 429) the SDK
171
+ retries — 3 times by default — with exponential backoff capped at 8s. So with an
172
+ unreachable aiwarden the caller can wait on the order of **ten seconds** before
173
+ getting the fail-open verdict, not the two the timeout suggests.
174
+
175
+ If your path is latency-sensitive, cap it:
176
+
177
+ ```python
178
+ client = Aiwarden(api_key="awd_live_...", retries=0) # answers on the first timeout
179
+ ```
180
+
181
+ ## Async
182
+
183
+ ```python
184
+ from aiwarden import AsyncAiwarden
185
+
186
+ async with AsyncAiwarden(api_key="awd_live_...") as client:
187
+ verdict = await client.analyze(prompt="...")
188
+ ```
189
+
190
+ ## Documentation
191
+
192
+ Full reference + integration guides at [platform.aiwarden.ai/documentation](https://platform.aiwarden.ai/documentation).
193
+
194
+ ## License
195
+
196
+ MIT
@@ -0,0 +1,164 @@
1
+ # aiwarden — Python SDK
2
+
3
+ Official Python client for [aiwarden](https://platform.aiwarden.ai) — AI governance, threat detection, and agent oversight.
4
+
5
+ > Status: alpha. API surface may change before `1.0.0`.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install aiwarden-sdk
11
+ ```
12
+
13
+ ## Quickstart
14
+
15
+ ```python
16
+ from aiwarden import Aiwarden
17
+
18
+ client = Aiwarden(api_key="awd_live_...")
19
+
20
+ # Per-request analysis (regex + AI threat detection, attachments supported)
21
+ verdict = client.analyze(prompt="Ignore all previous instructions")
22
+ print(verdict.action) # "block"
23
+
24
+ # Full agent governance (policies, rate limits, MCP, approvals, lineage)
25
+ result = client.agents.execute(
26
+ agent_id="my-foundry-agent",
27
+ action_type="llm_call",
28
+ prompt="Summarize this customer ticket",
29
+ user={"email": "alice@acme.com"},
30
+ )
31
+ if result.action == "block":
32
+ raise RuntimeError(result.reason)
33
+ ```
34
+
35
+ ## Agentic Endpoint: aiwarden inside your agent
36
+
37
+ Install the package in the agent's environment and it governs the whole agent:
38
+ every model call and every tool it is about to run is checked with aiwarden
39
+ first, and the verdict is applied (allow, block, hold for approval).
40
+
41
+ ```bash
42
+ pip install aiwarden-sdk
43
+ export AIWARDEN_INSTALL_CODE=aep_...
44
+ export AIWARDEN_AGENT_ID=billing-agent # optional; defaults to <script>@<host>
45
+ ```
46
+
47
+ The install code (created in the portal, Integrations → Agentic Endpoint)
48
+ expires and has a limit of uses. On its first start the agent swaps it for a
49
+ credential of its own, kept in `~/.aiwarden` (owner-only), so your account key
50
+ never reaches the machine the agent runs on. An agent without a disk has
51
+ nowhere to keep it: start that one with `AIWARDEN_API_KEY=<your agents key>`
52
+ instead.
53
+
54
+ One line at the top of the agent:
55
+
56
+ ```python
57
+ import aiwarden.endpoint as endpoint
58
+ endpoint.install()
59
+ ```
60
+
61
+ Or no code change at all:
62
+
63
+ ```bash
64
+ aiwarden-run python my_agent.py
65
+ ```
66
+
67
+ What it attaches to (verified against the real libraries in `tests/test_endpoint.py`
68
+ and `tests/test_endpoint_frameworks.py`):
69
+
70
+ | Where | What is checked |
71
+ |---|---|
72
+ | OpenAI client (`chat.completions`, `responses`) | the person's message, the tools the model asks for, and tool results before the model reads them |
73
+ | Anthropic client (`messages`) | same |
74
+ | LangChain / LangGraph tools | the moment a tool runs, and its output |
75
+ | OpenAI Agents SDK (`openai-agents`) function tools | the moment a tool runs, and its output (`Runner.run` and `Runner.run_streamed`, Responses and Chat Completions) |
76
+ | CrewAI tools | the moment a tool runs, and its output (native tool calls and ReAct, any model provider) |
77
+ | Your own functions | `@endpoint.guarded` |
78
+
79
+ Because it hooks the model client itself, it also covers agents written with
80
+ plain API calls and any framework that calls OpenAI or Anthropic through their
81
+ SDKs.
82
+
83
+ A blocked tool never runs. By default the model is told with a neutral message
84
+ and the agent goes on (`AIWARDEN_ON_BLOCK=replace`); with `raise`,
85
+ `aiwarden.endpoint.AiwardenBlocked` is raised. `endpoint.set_user(email)` tells
86
+ aiwarden on whose behalf the agent is acting. `endpoint.status()` shows what is
87
+ attached and how many actions were checked, blocked, or let through without a
88
+ verdict.
89
+
90
+ Fail-open: if aiwarden cannot be reached, the agent keeps working and the
91
+ action is counted as `ungoverned`.
92
+
93
+ Streaming is governed too (`create(stream=True)` in both clients): text flows
94
+ as it arrives and only the events that ask for a tool are held until aiwarden
95
+ answers.
96
+
97
+ What the model answers is sent back to aiwarden off the agent's path (text of
98
+ the last answer of a turn, real tokens, time of the call), so the agent's cost
99
+ and its answers show up in aiwarden. When the policy's containment can change
100
+ an answer (retry once, hold or close the session), the package waits for
101
+ aiwarden's verdict on it; otherwise nothing waits. A short-lived agent should
102
+ call `endpoint.flush()` before exiting.
103
+
104
+ Known limits: the `.stream()` helpers of both SDKs (`chat.completions.stream`,
105
+ `responses.stream`, `messages.stream`) are checked on the request side only
106
+ (`create(stream=True)` is fully governed in the three APIs); a blocked tool
107
+ call in the non-streamed Responses API always raises (not inside the OpenAI
108
+ Agents SDK, where the tool is decided when it runs); answers asked for through
109
+ `with_raw_response` / `with_streaming_response` are checked on the request side
110
+ only (CrewAI's OpenAI provider does this: its tools are governed by the CrewAI
111
+ hook, but that model's answers and tokens are not reported); MCP clients do not
112
+ have their own hook yet. In the OpenAI Agents SDK, handoffs are checked at the
113
+ model only, and hosted, shell, computer and custom tools are not checked. In
114
+ CrewAI, the model call is governed only for the providers that use the OpenAI
115
+ or Anthropic SDK; `on_block=raise` cannot leave a CrewAI hook, so a denied tool
116
+ is blocked and the model told; and a crew that clears CrewAI's tool hooks
117
+ removes aiwarden's too.
118
+
119
+ ## What this SDK covers (v0.1)
120
+
121
+ - `client.analyze()` — `POST /analyze` (per-request, supports text + attachments).
122
+ - `client.ask()` — `POST /ask` (full proxy LLM flow with detection + intel logging).
123
+ - `client.agents.execute()` — `POST /api/agent/v1/execute` (full agent governance pipeline).
124
+ - `client.agents.register()` — `POST /api/agent/v1/register`.
125
+ - `client.agents.list_tools()` — `GET /api/agent/v1/tools`.
126
+ - `client.agents.status()` — `GET /api/agent/v1/status`.
127
+
128
+ ## Fail mode
129
+
130
+ By default the SDK is **fail-open**: if aiwarden times out or errors, your agent continues without governance (a `WARN` is logged). Switch to strict for regulated workloads:
131
+
132
+ ```python
133
+ client = Aiwarden(api_key="awd_live_...", fail_mode="closed", timeout=2.0)
134
+ ```
135
+
136
+ ### Latency budget
137
+
138
+ `timeout` is **per attempt**. On a transient failure (network, 5xx, 429) the SDK
139
+ retries — 3 times by default — with exponential backoff capped at 8s. So with an
140
+ unreachable aiwarden the caller can wait on the order of **ten seconds** before
141
+ getting the fail-open verdict, not the two the timeout suggests.
142
+
143
+ If your path is latency-sensitive, cap it:
144
+
145
+ ```python
146
+ client = Aiwarden(api_key="awd_live_...", retries=0) # answers on the first timeout
147
+ ```
148
+
149
+ ## Async
150
+
151
+ ```python
152
+ from aiwarden import AsyncAiwarden
153
+
154
+ async with AsyncAiwarden(api_key="awd_live_...") as client:
155
+ verdict = await client.analyze(prompt="...")
156
+ ```
157
+
158
+ ## Documentation
159
+
160
+ Full reference + integration guides at [platform.aiwarden.ai/documentation](https://platform.aiwarden.ai/documentation).
161
+
162
+ ## License
163
+
164
+ MIT
@@ -0,0 +1,37 @@
1
+ """Official Python client for aiwarden."""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ from aiwarden._models import (
6
+ AnalyzeRequest,
7
+ AskRequest,
8
+ ExecuteRequest,
9
+ RegisterRequest,
10
+ ThreatEvent,
11
+ UserContext,
12
+ Verdict,
13
+ )
14
+ from aiwarden.client import Aiwarden, AsyncAiwarden
15
+ from aiwarden.exceptions import (
16
+ AiwardenAuthError,
17
+ AiwardenBlocked,
18
+ AiwardenError,
19
+ AiwardenTimeout,
20
+ )
21
+
22
+ __all__ = [
23
+ "Aiwarden",
24
+ "AsyncAiwarden",
25
+ "AiwardenAuthError",
26
+ "AiwardenBlocked",
27
+ "AiwardenError",
28
+ "AiwardenTimeout",
29
+ "AnalyzeRequest",
30
+ "AskRequest",
31
+ "ExecuteRequest",
32
+ "RegisterRequest",
33
+ "ThreatEvent",
34
+ "UserContext",
35
+ "Verdict",
36
+ "__version__",
37
+ ]
@@ -0,0 +1,138 @@
1
+ """Pydantic request/response models. Mirror of backend schemas verified against:
2
+ - aiwarden_proxy.py:361 (AskRequest) and :2682 (AnalyzeRequest)
3
+ - portals/user/backend/routes/agent_gateway.py:140 (ExecuteRequest), :163 (RegisterRequest)
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import Any, Dict, List, Optional
9
+
10
+ from pydantic import BaseModel, Field
11
+
12
+
13
+ # ── Shared user/identity context ────────────────────────────────────
14
+
15
+
16
+ class UserContext(BaseModel):
17
+ """User behind the request. Same shape as agent_gateway.py UserContext."""
18
+
19
+ email: Optional[str] = None
20
+ user_id: Optional[str] = None
21
+ role: Optional[str] = None
22
+ department: Optional[str] = None
23
+
24
+
25
+ # ── /ask request ────────────────────────────────────────────────────
26
+
27
+
28
+ class AskRequest(BaseModel):
29
+ prompt: str
30
+ model: Optional[str] = "gpt-4o"
31
+ session_id: Optional[str] = None
32
+ industry: Optional[str] = None
33
+ user_id: Optional[str] = None
34
+ user_email: Optional[str] = None
35
+ user_name: Optional[str] = None
36
+ department: Optional[str] = None
37
+ organization_id: Optional[str] = None
38
+ hostname: Optional[str] = None
39
+ device_id: Optional[str] = None
40
+ application_name: Optional[str] = None
41
+
42
+
43
+ # ── /analyze request ────────────────────────────────────────────────
44
+
45
+
46
+ class AnalyzeRequest(BaseModel):
47
+ prompt: str = ""
48
+ model: Optional[str] = None
49
+ session_id: Optional[str] = None
50
+ industry: Optional[str] = None
51
+ user_id: Optional[str] = None
52
+ user_email: Optional[str] = None
53
+ user_name: Optional[str] = None
54
+ department: Optional[str] = None
55
+ organization_id: Optional[str] = None
56
+ hostname: Optional[str] = None
57
+ device_id: Optional[str] = None
58
+ application_name: Optional[str] = None
59
+
60
+
61
+ # ── Agent Gateway ─────────────────────────────────────────────────
62
+
63
+
64
+ class ExecuteRequest(BaseModel):
65
+ """POST /api/agent/v1/execute — full agent governance pipeline."""
66
+
67
+ agent_id: str
68
+ action_type: str = Field(..., description="'llm_call' or 'tool_use'")
69
+ prompt: Optional[str] = None
70
+ model: Optional[str] = None
71
+ tool_name: Optional[str] = None
72
+ tool_params: Optional[Dict[str, Any]] = None
73
+ response_text: Optional[str] = None
74
+ user: Optional[UserContext] = None
75
+ session_id: Optional[str] = None
76
+ step_number: Optional[int] = None
77
+ metadata: Optional[Dict[str, Any]] = None
78
+
79
+
80
+ class RegisterRequest(BaseModel):
81
+ """POST /api/agent/v1/register"""
82
+
83
+ agent_id: str
84
+ name: str
85
+ description: Optional[str] = None
86
+ purpose: Optional[str] = None
87
+ allowed_tools: List[str] = Field(default_factory=list)
88
+ allowed_models: List[str] = Field(default_factory=list)
89
+ requires_user_context: bool = True
90
+ max_actions_hour: int = 100
91
+ max_cost_day_usd: float = 10.0
92
+ compliance_scope: List[str] = Field(default_factory=list)
93
+ owner_email: Optional[str] = None
94
+
95
+
96
+ # ── Response models ────────────────────────────────────────────────
97
+
98
+
99
+ class ThreatEvent(BaseModel):
100
+ """One threat detection event from the hybrid detector."""
101
+
102
+ rule_id: Optional[str] = None
103
+ rule_name: Optional[str] = None
104
+ category: Optional[str] = None
105
+ severity: Optional[str] = None
106
+ description: Optional[str] = None
107
+ detection_source: Optional[str] = None
108
+ matched_pattern: Optional[str] = None
109
+ detection_layer: Optional[int] = None
110
+ detection_layer_name: Optional[str] = None
111
+
112
+ model_config = {"extra": "allow"}
113
+
114
+
115
+ class Verdict(BaseModel):
116
+ """Generic verdict for analyze / agent.execute responses."""
117
+
118
+ action: str = Field(..., description="'allow' | 'block' | 'warn' | 'filter' | 'pending_approval'")
119
+ permission: Optional[str] = None
120
+ reason: Optional[str] = None
121
+ threats: List[ThreatEvent] = Field(default_factory=list)
122
+ processing_ms: Optional[int] = None
123
+ awaiting_approval: bool = False
124
+ blocked: bool = False
125
+ filtered_prompt: Optional[str] = None
126
+ tool_result: Optional[Dict[str, Any]] = None
127
+ rate_limit: Optional[Dict[str, Any]] = None
128
+ raw: Optional[Dict[str, Any]] = Field(default=None, exclude=True)
129
+
130
+ model_config = {"extra": "allow"}
131
+
132
+ @property
133
+ def is_allowed(self) -> bool:
134
+ return self.action in ("allow", "filter", "warn")
135
+
136
+ @property
137
+ def is_blocked(self) -> bool:
138
+ return self.action == "block" or self.blocked