cortexhub 0.4.0__tar.gz → 0.4.2__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.
- {cortexhub-0.4.0 → cortexhub-0.4.2}/PKG-INFO +1 -1
- {cortexhub-0.4.0 → cortexhub-0.4.2}/pyproject.toml +1 -1
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/__init__.py +0 -4
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/backend/client.py +15 -2
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/client.py +13 -127
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/errors.py +0 -18
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/policy/effects.py +0 -40
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/policy/evaluator.py +1 -17
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/tool.py +0 -2
- {cortexhub-0.4.0 → cortexhub-0.4.2}/.gitignore +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/LICENSE +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/README.md +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/audit/__init__.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/audit/events.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/backend/__init__.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/config.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/constants.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/context/__init__.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/context/enricher.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/__init__.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/injection.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/__init__.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/LICENSE +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/LICENSES_SOURCES +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/README.md +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/accuracy.json +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/attribute_ruler/patterns +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/config.cfg +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/lemmatizer/lookups/lookups.bin +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/meta.json +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/ner/cfg +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/ner/model +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/ner/moves +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/parser/cfg +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/parser/model +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/parser/moves +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/senter/cfg +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/senter/model +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tagger/cfg +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tagger/model +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tok2vec/cfg +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tok2vec/model +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tokenizer +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/key2row +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/lookups.bin +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/strings.json +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/vectors +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/vectors.cfg +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/meta.json +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/pii.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/secrets.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/interceptors/__init__.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/interceptors/mcp.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/logging.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/policy/__init__.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/policy/loader.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/policy/models.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/policy/sync.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/signing.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/telemetry/__init__.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/telemetry/otel.py +0 -0
- {cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cortexhub
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: CortexHub Python SDK — Runtime governance for AI systems. One decorator, any tool, any framework.
|
|
5
5
|
Project-URL: Homepage, https://cortexhub.ai
|
|
6
6
|
Project-URL: Documentation, https://docs.cortexhub.ai
|
|
@@ -35,8 +35,6 @@ from cortexhub.errors import (
|
|
|
35
35
|
GuardrailViolationError,
|
|
36
36
|
ApprovalRequiredError,
|
|
37
37
|
ApprovalDeniedError,
|
|
38
|
-
ThrottleError,
|
|
39
|
-
CircuitBreakError,
|
|
40
38
|
PolicyLoadError,
|
|
41
39
|
)
|
|
42
40
|
from cortexhub.signing import verify_signature
|
|
@@ -120,7 +118,5 @@ __all__ = [
|
|
|
120
118
|
"GuardrailViolationError",
|
|
121
119
|
"ApprovalRequiredError",
|
|
122
120
|
"ApprovalDeniedError",
|
|
123
|
-
"ThrottleError",
|
|
124
|
-
"CircuitBreakError",
|
|
125
121
|
"PolicyLoadError",
|
|
126
122
|
]
|
|
@@ -150,7 +150,16 @@ class BackendClient:
|
|
|
150
150
|
)
|
|
151
151
|
|
|
152
152
|
if response.status_code == 200:
|
|
153
|
-
|
|
153
|
+
try:
|
|
154
|
+
data = response.json()
|
|
155
|
+
except Exception as parse_err:
|
|
156
|
+
logger.error(
|
|
157
|
+
"Agent key validate returned non-JSON body",
|
|
158
|
+
status=response.status_code,
|
|
159
|
+
preview=(response.text or "")[:300],
|
|
160
|
+
error=str(parse_err),
|
|
161
|
+
)
|
|
162
|
+
return False, None
|
|
154
163
|
|
|
155
164
|
# Check if valid
|
|
156
165
|
if not data.get("valid", False):
|
|
@@ -306,7 +315,11 @@ class BackendClient:
|
|
|
306
315
|
logger.info("Policy bundle source (full)", policies=policies_str)
|
|
307
316
|
return True, config
|
|
308
317
|
else:
|
|
309
|
-
|
|
318
|
+
try:
|
|
319
|
+
body = response.json()
|
|
320
|
+
error_detail = body.get("detail", "Invalid agent key") if isinstance(body, dict) else str(body)
|
|
321
|
+
except Exception:
|
|
322
|
+
error_detail = (response.text or "")[:500] or f"HTTP {response.status_code}"
|
|
310
323
|
logger.warning("Agent key validation failed", error=error_detail)
|
|
311
324
|
return False, None
|
|
312
325
|
|
|
@@ -26,6 +26,7 @@ import hashlib
|
|
|
26
26
|
import json
|
|
27
27
|
import math
|
|
28
28
|
import os
|
|
29
|
+
import sys
|
|
29
30
|
import threading
|
|
30
31
|
import time
|
|
31
32
|
import uuid
|
|
@@ -50,8 +51,6 @@ from cortexhub.errors import (
|
|
|
50
51
|
ApprovalRequiredError,
|
|
51
52
|
ApprovalDeniedError,
|
|
52
53
|
PolicyViolationError,
|
|
53
|
-
ThrottleError,
|
|
54
|
-
CircuitBreakError,
|
|
55
54
|
)
|
|
56
55
|
from cortexhub.audit.events import LLMGuardrailFindings
|
|
57
56
|
from cortexhub.guardrails.injection import PromptManipulationDetector
|
|
@@ -77,6 +76,16 @@ from cortexhub.constants import (
|
|
|
77
76
|
from cortexhub.version import __version__
|
|
78
77
|
|
|
79
78
|
logger = structlog.get_logger(__name__)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _flatten_exception_for_log(exc: BaseException) -> str:
|
|
82
|
+
"""Readable one-line-ish message; expands ExceptionGroup on 3.11+ (e.g. MCP httpx TaskGroup)."""
|
|
83
|
+
if sys.version_info >= (3, 11) and isinstance(exc, BaseExceptionGroup):
|
|
84
|
+
inner = "; ".join(_flatten_exception_for_log(e) for e in exc.exceptions)
|
|
85
|
+
return f"{type(exc).__name__}: {exc} | {inner}"
|
|
86
|
+
return f"{type(exc).__name__}: {exc}"
|
|
87
|
+
|
|
88
|
+
|
|
80
89
|
_run_depth: contextvars.ContextVar[int] = contextvars.ContextVar("cortexhub_run_depth", default=0)
|
|
81
90
|
_run_id_var: contextvars.ContextVar[str | None] = contextvars.ContextVar(
|
|
82
91
|
"cortexhub_run_id",
|
|
@@ -269,7 +278,6 @@ class CortexHub:
|
|
|
269
278
|
self._sdk_config = None # SDKConfig from backend
|
|
270
279
|
self._run_id: str | None = None # current/last run id (for approval resume)
|
|
271
280
|
self._tool_inventory_cache: set[str] = set()
|
|
272
|
-
self._circuit_breakers: dict[str, dict[str, str]] = {}
|
|
273
281
|
self._run_started_at = time.monotonic()
|
|
274
282
|
self._run_prompt_tokens = 0
|
|
275
283
|
self._run_completion_tokens = 0
|
|
@@ -1212,28 +1220,6 @@ class CortexHub:
|
|
|
1212
1220
|
schema_hash = hashlib.sha256(payload.encode()).hexdigest()[:16] if names else ""
|
|
1213
1221
|
return f"{framework}:{tool_name}:{schema_hash}"
|
|
1214
1222
|
|
|
1215
|
-
def _circuit_breaker_key(self, action_type: str, action_name: str) -> str:
|
|
1216
|
-
return f"{action_type}:{action_name}"
|
|
1217
|
-
|
|
1218
|
-
def _is_circuit_open(self, action_type: str, action_name: str) -> dict[str, str] | None:
|
|
1219
|
-
return self._circuit_breakers.get(self._circuit_breaker_key(action_type, action_name))
|
|
1220
|
-
|
|
1221
|
-
def _open_circuit(
|
|
1222
|
-
self,
|
|
1223
|
-
*,
|
|
1224
|
-
action_type: str,
|
|
1225
|
-
action_name: str,
|
|
1226
|
-
policy_id: str | None,
|
|
1227
|
-
policy_name: str | None,
|
|
1228
|
-
reason: str,
|
|
1229
|
-
) -> None:
|
|
1230
|
-
key = self._circuit_breaker_key(action_type, action_name)
|
|
1231
|
-
self._circuit_breakers[key] = {
|
|
1232
|
-
"policy_id": policy_id or "",
|
|
1233
|
-
"policy_name": policy_name or "",
|
|
1234
|
-
"reason": reason,
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
1223
|
def _sanitize_schema(self, value: Any) -> Any:
|
|
1238
1224
|
if isinstance(value, dict):
|
|
1239
1225
|
sanitized = {str(k): self._sanitize_schema(v) for k, v in value.items()}
|
|
@@ -1373,7 +1359,7 @@ class CortexHub:
|
|
|
1373
1359
|
logger.error(
|
|
1374
1360
|
"SDK internal error in governance pipeline — executing tool without governance",
|
|
1375
1361
|
tool_name=tool_name,
|
|
1376
|
-
error=
|
|
1362
|
+
error=_flatten_exception_for_log(_sdk_err),
|
|
1377
1363
|
error_type=type(_sdk_err).__name__,
|
|
1378
1364
|
)
|
|
1379
1365
|
return _call_original_ref()
|
|
@@ -1468,22 +1454,6 @@ class CortexHub:
|
|
|
1468
1454
|
span.set_attribute("cortexhub.raw.args", payload)
|
|
1469
1455
|
|
|
1470
1456
|
try:
|
|
1471
|
-
if self._policy_evaluation_enabled():
|
|
1472
|
-
breaker = self._is_circuit_open("tool.invoke", tool_name)
|
|
1473
|
-
if breaker:
|
|
1474
|
-
reason = breaker.get("reason") or "Circuit breaker open"
|
|
1475
|
-
decision = Decision.circuit_break(
|
|
1476
|
-
reasoning=reason,
|
|
1477
|
-
policy_id=breaker.get("policy_id") or None,
|
|
1478
|
-
policy_name=breaker.get("policy_name") or None,
|
|
1479
|
-
)
|
|
1480
|
-
span.add_event(
|
|
1481
|
-
"policy.decision",
|
|
1482
|
-
attributes=self._decision_event_attributes(decision),
|
|
1483
|
-
)
|
|
1484
|
-
span.set_status(Status(StatusCode.ERROR, reason))
|
|
1485
|
-
raise CircuitBreakError(reason, policy_id=decision.policy_id, reasoning=reason)
|
|
1486
|
-
|
|
1487
1457
|
if expected_types and self._policy_evaluation_enabled():
|
|
1488
1458
|
mismatches = self._validate_arg_types(args, expected_types)
|
|
1489
1459
|
if mismatches:
|
|
@@ -1536,37 +1506,6 @@ class CortexHub:
|
|
|
1536
1506
|
if decision.effect == Effect.PERMIT:
|
|
1537
1507
|
pass
|
|
1538
1508
|
|
|
1539
|
-
if decision.effect == Effect.THROTTLE:
|
|
1540
|
-
span.add_event(
|
|
1541
|
-
"policy.decision",
|
|
1542
|
-
attributes=self._decision_event_attributes(decision),
|
|
1543
|
-
)
|
|
1544
|
-
span.set_status(Status(StatusCode.ERROR, decision.reasoning))
|
|
1545
|
-
raise ThrottleError(
|
|
1546
|
-
decision.reasoning,
|
|
1547
|
-
policy_id=decision.policy_id,
|
|
1548
|
-
reasoning=decision.reasoning,
|
|
1549
|
-
)
|
|
1550
|
-
|
|
1551
|
-
if decision.effect == Effect.CIRCUIT_BREAK:
|
|
1552
|
-
span.add_event(
|
|
1553
|
-
"policy.decision",
|
|
1554
|
-
attributes=self._decision_event_attributes(decision),
|
|
1555
|
-
)
|
|
1556
|
-
self._open_circuit(
|
|
1557
|
-
action_type="tool.invoke",
|
|
1558
|
-
action_name=tool_name,
|
|
1559
|
-
policy_id=decision.policy_id,
|
|
1560
|
-
policy_name=decision.policy_name,
|
|
1561
|
-
reason=decision.reasoning,
|
|
1562
|
-
)
|
|
1563
|
-
span.set_status(Status(StatusCode.ERROR, decision.reasoning))
|
|
1564
|
-
raise CircuitBreakError(
|
|
1565
|
-
decision.reasoning,
|
|
1566
|
-
policy_id=decision.policy_id,
|
|
1567
|
-
reasoning=decision.reasoning,
|
|
1568
|
-
)
|
|
1569
|
-
|
|
1570
1509
|
if decision and decision.effect == Effect.DENY:
|
|
1571
1510
|
span.add_event(
|
|
1572
1511
|
"policy.decision",
|
|
@@ -1783,8 +1722,6 @@ class CortexHub:
|
|
|
1783
1722
|
PolicyViolationError,
|
|
1784
1723
|
ApprovalRequiredError,
|
|
1785
1724
|
ApprovalDeniedError,
|
|
1786
|
-
ThrottleError,
|
|
1787
|
-
CircuitBreakError,
|
|
1788
1725
|
):
|
|
1789
1726
|
# These are expected governance failures - re-raise
|
|
1790
1727
|
raise
|
|
@@ -1830,7 +1767,7 @@ class CortexHub:
|
|
|
1830
1767
|
logger.error(
|
|
1831
1768
|
"SDK internal error in async governance pipeline — executing tool without governance",
|
|
1832
1769
|
tool_name=tool_name,
|
|
1833
|
-
error=
|
|
1770
|
+
error=_flatten_exception_for_log(_sdk_err),
|
|
1834
1771
|
error_type=type(_sdk_err).__name__,
|
|
1835
1772
|
)
|
|
1836
1773
|
return await _call_original_ref()
|
|
@@ -1911,22 +1848,6 @@ class CortexHub:
|
|
|
1911
1848
|
span.set_attribute("cortexhub.raw.args", payload)
|
|
1912
1849
|
|
|
1913
1850
|
try:
|
|
1914
|
-
if self._policy_evaluation_enabled():
|
|
1915
|
-
breaker = self._is_circuit_open("tool.invoke", tool_name)
|
|
1916
|
-
if breaker:
|
|
1917
|
-
reason = breaker.get("reason") or "Circuit breaker open"
|
|
1918
|
-
decision = Decision.circuit_break(
|
|
1919
|
-
reasoning=reason,
|
|
1920
|
-
policy_id=breaker.get("policy_id") or None,
|
|
1921
|
-
policy_name=breaker.get("policy_name") or None,
|
|
1922
|
-
)
|
|
1923
|
-
span.add_event(
|
|
1924
|
-
"policy.decision",
|
|
1925
|
-
attributes=self._decision_event_attributes(decision),
|
|
1926
|
-
)
|
|
1927
|
-
span.set_status(Status(StatusCode.ERROR, reason))
|
|
1928
|
-
raise CircuitBreakError(reason, policy_id=decision.policy_id, reasoning=reason)
|
|
1929
|
-
|
|
1930
1851
|
if expected_types and self._policy_evaluation_enabled():
|
|
1931
1852
|
mismatches = self._validate_arg_types(args, expected_types)
|
|
1932
1853
|
if mismatches:
|
|
@@ -1970,37 +1891,6 @@ class CortexHub:
|
|
|
1970
1891
|
if decision.effect == Effect.PERMIT:
|
|
1971
1892
|
pass
|
|
1972
1893
|
|
|
1973
|
-
if decision.effect == Effect.THROTTLE:
|
|
1974
|
-
span.add_event(
|
|
1975
|
-
"policy.decision",
|
|
1976
|
-
attributes=self._decision_event_attributes(decision),
|
|
1977
|
-
)
|
|
1978
|
-
span.set_status(Status(StatusCode.ERROR, decision.reasoning))
|
|
1979
|
-
raise ThrottleError(
|
|
1980
|
-
decision.reasoning,
|
|
1981
|
-
policy_id=decision.policy_id,
|
|
1982
|
-
reasoning=decision.reasoning,
|
|
1983
|
-
)
|
|
1984
|
-
|
|
1985
|
-
if decision.effect == Effect.CIRCUIT_BREAK:
|
|
1986
|
-
span.add_event(
|
|
1987
|
-
"policy.decision",
|
|
1988
|
-
attributes=self._decision_event_attributes(decision),
|
|
1989
|
-
)
|
|
1990
|
-
self._open_circuit(
|
|
1991
|
-
action_type="tool.invoke",
|
|
1992
|
-
action_name=tool_name,
|
|
1993
|
-
policy_id=decision.policy_id,
|
|
1994
|
-
policy_name=decision.policy_name,
|
|
1995
|
-
reason=decision.reasoning,
|
|
1996
|
-
)
|
|
1997
|
-
span.set_status(Status(StatusCode.ERROR, decision.reasoning))
|
|
1998
|
-
raise CircuitBreakError(
|
|
1999
|
-
decision.reasoning,
|
|
2000
|
-
policy_id=decision.policy_id,
|
|
2001
|
-
reasoning=decision.reasoning,
|
|
2002
|
-
)
|
|
2003
|
-
|
|
2004
1894
|
if decision and decision.effect == Effect.DENY:
|
|
2005
1895
|
span.add_event(
|
|
2006
1896
|
"policy.decision",
|
|
@@ -2207,8 +2097,6 @@ class CortexHub:
|
|
|
2207
2097
|
PolicyViolationError,
|
|
2208
2098
|
ApprovalRequiredError,
|
|
2209
2099
|
ApprovalDeniedError,
|
|
2210
|
-
ThrottleError,
|
|
2211
|
-
CircuitBreakError,
|
|
2212
2100
|
):
|
|
2213
2101
|
raise
|
|
2214
2102
|
except Exception as e:
|
|
@@ -3532,8 +3420,6 @@ class CortexHub:
|
|
|
3532
3420
|
Raises:
|
|
3533
3421
|
PolicyViolationError: Policy blocked the action.
|
|
3534
3422
|
ApprovalRequiredError: Human approval required before proceeding.
|
|
3535
|
-
ThrottleError: Rate-limit policy triggered.
|
|
3536
|
-
CircuitBreakError: Circuit breaker is open.
|
|
3537
3423
|
"""
|
|
3538
3424
|
self.execute_governed_tool(
|
|
3539
3425
|
tool_name=tool_name,
|
|
@@ -144,24 +144,6 @@ class ApprovalDeniedError(CortexHubError):
|
|
|
144
144
|
self.reason = reason
|
|
145
145
|
|
|
146
146
|
|
|
147
|
-
class ThrottleError(CortexHubError):
|
|
148
|
-
"""Raised when a policy rate-limits a tool invocation."""
|
|
149
|
-
|
|
150
|
-
def __init__(self, message: str, policy_id: str | None = None, reasoning: str = ""):
|
|
151
|
-
super().__init__(message)
|
|
152
|
-
self.policy_id = policy_id
|
|
153
|
-
self.reasoning = reasoning
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
class CircuitBreakError(CortexHubError):
|
|
157
|
-
"""Raised when a circuit breaker blocks execution."""
|
|
158
|
-
|
|
159
|
-
def __init__(self, message: str, policy_id: str | None = None, reasoning: str = ""):
|
|
160
|
-
super().__init__(message)
|
|
161
|
-
self.policy_id = policy_id
|
|
162
|
-
self.reasoning = reasoning
|
|
163
|
-
|
|
164
|
-
|
|
165
147
|
class PolicyLoadError(CortexHubError):
|
|
166
148
|
"""Raised when policy bundle cannot be loaded or is invalid."""
|
|
167
149
|
|
|
@@ -16,8 +16,6 @@ class Effect(str, Enum):
|
|
|
16
16
|
DENY = "deny"
|
|
17
17
|
ESCALATE = "escalate"
|
|
18
18
|
REDACT = "redact" # PII/secrets were redacted before LLM call
|
|
19
|
-
THROTTLE = "throttle"
|
|
20
|
-
CIRCUIT_BREAK = "circuit_break"
|
|
21
19
|
|
|
22
20
|
|
|
23
21
|
class Decision(BaseModel):
|
|
@@ -149,44 +147,6 @@ class Decision(BaseModel):
|
|
|
149
147
|
policy_decisions=policy_decisions,
|
|
150
148
|
)
|
|
151
149
|
|
|
152
|
-
@classmethod
|
|
153
|
-
def throttle(
|
|
154
|
-
cls,
|
|
155
|
-
reasoning: str,
|
|
156
|
-
policy_id: str | None = None,
|
|
157
|
-
policy_name: str | None = None,
|
|
158
|
-
policy_effect: str | None = None,
|
|
159
|
-
policy_decisions: list[dict[str, str | None]] | None = None,
|
|
160
|
-
):
|
|
161
|
-
"""Create a THROTTLE decision (rate-limit execution)."""
|
|
162
|
-
return cls(
|
|
163
|
-
effect=Effect.THROTTLE,
|
|
164
|
-
reasoning=reasoning,
|
|
165
|
-
policy_id=policy_id,
|
|
166
|
-
policy_name=policy_name,
|
|
167
|
-
policy_effect=policy_effect,
|
|
168
|
-
policy_decisions=policy_decisions,
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
@classmethod
|
|
172
|
-
def circuit_break(
|
|
173
|
-
cls,
|
|
174
|
-
reasoning: str,
|
|
175
|
-
policy_id: str | None = None,
|
|
176
|
-
policy_name: str | None = None,
|
|
177
|
-
policy_effect: str | None = None,
|
|
178
|
-
policy_decisions: list[dict[str, str | None]] | None = None,
|
|
179
|
-
):
|
|
180
|
-
"""Create a CIRCUIT_BREAK decision (open circuit for this action)."""
|
|
181
|
-
return cls(
|
|
182
|
-
effect=Effect.CIRCUIT_BREAK,
|
|
183
|
-
reasoning=reasoning,
|
|
184
|
-
policy_id=policy_id,
|
|
185
|
-
policy_name=policy_name,
|
|
186
|
-
policy_effect=policy_effect,
|
|
187
|
-
policy_decisions=policy_decisions,
|
|
188
|
-
)
|
|
189
|
-
|
|
190
150
|
def is_redacted(self) -> bool:
|
|
191
151
|
"""Check if the decision resulted in redaction."""
|
|
192
152
|
return self.effect == Effect.REDACT
|
|
@@ -278,7 +278,7 @@ class PolicyEvaluator:
|
|
|
278
278
|
policy_decisions=policy_decisions,
|
|
279
279
|
)
|
|
280
280
|
# Multiple forbids can match (e.g. hard deny + require_approval). Apply effect priority:
|
|
281
|
-
# block > require_approval >
|
|
281
|
+
# block > require_approval > generic deny.
|
|
282
282
|
reasons = result.diagnostics.reasons or []
|
|
283
283
|
effects_seen = set()
|
|
284
284
|
first_policy_id, first_policy_name, first_effect = None, None, None
|
|
@@ -312,22 +312,6 @@ class PolicyEvaluator:
|
|
|
312
312
|
policy_decisions=policy_decisions,
|
|
313
313
|
policy_timeout_behavior=timeout_behavior if timeout_behavior in ("deny", "allow") else "deny",
|
|
314
314
|
)
|
|
315
|
-
if "throttle" in effects_seen:
|
|
316
|
-
return Decision.throttle(
|
|
317
|
-
reasoning="Throttled by policy",
|
|
318
|
-
policy_id=policy_id,
|
|
319
|
-
policy_name=policy_name,
|
|
320
|
-
policy_effect="throttle",
|
|
321
|
-
policy_decisions=policy_decisions,
|
|
322
|
-
)
|
|
323
|
-
if "circuit_break" in effects_seen:
|
|
324
|
-
return Decision.circuit_break(
|
|
325
|
-
reasoning="Circuit breaker triggered by policy",
|
|
326
|
-
policy_id=policy_id,
|
|
327
|
-
policy_name=policy_name,
|
|
328
|
-
policy_effect="circuit_break",
|
|
329
|
-
policy_decisions=policy_decisions,
|
|
330
|
-
)
|
|
331
315
|
return Decision.deny(
|
|
332
316
|
reasoning="Denied by CortexHub Policy",
|
|
333
317
|
policy_id=policy_id,
|
|
@@ -79,8 +79,6 @@ class GovernedTool:
|
|
|
79
79
|
-----------------
|
|
80
80
|
- ``PolicyViolationError`` — policy blocked execution
|
|
81
81
|
- ``ApprovalRequiredError`` — human approval needed
|
|
82
|
-
- ``ThrottleError`` — rate limit triggered
|
|
83
|
-
- ``CircuitBreakError`` — circuit breaker open
|
|
84
82
|
|
|
85
83
|
Framework compatibility
|
|
86
84
|
-----------------------
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cortexhub-0.4.0 → cortexhub-0.4.2}/src/cortexhub/guardrails/models/en_core_web_sm/meta.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|