trustmodel 3.8.0__tar.gz → 3.9.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.
- {trustmodel-3.8.0 → trustmodel-3.9.0}/PKG-INFO +1 -1
- {trustmodel-3.8.0 → trustmodel-3.9.0}/pyproject.toml +1 -1
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/endpoints/_runtime_transport.py +35 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/endpoints/guardrails.py +82 -15
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/models/guardrails.py +12 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/.gitignore +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/LICENSE +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/README.md +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/__init__.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/cli.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/client.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/compat.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/endpoints/__init__.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/endpoints/agentcert.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/endpoints/agentic.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/endpoints/batch_jobs.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/endpoints/config.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/endpoints/credits.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/endpoints/evaluations.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/endpoints/frameworks.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/endpoints/galileo.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/endpoints/mcp_scanner.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/endpoints/models.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/exceptions.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/models/__init__.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/models/agentcert.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/models/agentic.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/models/batch_job.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/models/credits.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/models/evaluation.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/models/frameworks.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/models/galileo.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/models/mcp_scanner.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/models/models.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/models/oauth.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/oauth/__init__.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/oauth/auth.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/oauth/scopes.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/telemetry/__init__.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/telemetry/_constants.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/telemetry/_instrumentors.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/telemetry/auto_init.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/utils/__init__.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/utils/validation.py +0 -0
- {trustmodel-3.8.0 → trustmodel-3.9.0}/src/trustmodel/utils/version.py +0 -0
|
@@ -45,6 +45,41 @@ class TransportError(Exception):
|
|
|
45
45
|
self.cause = cause
|
|
46
46
|
super().__init__(message)
|
|
47
47
|
|
|
48
|
+
@property
|
|
49
|
+
def is_availability_failure(self) -> bool:
|
|
50
|
+
"""True when this failure means "the service could not answer".
|
|
51
|
+
|
|
52
|
+
TRUS-2159. ``fail_mode`` is an availability trade-off: a caller who
|
|
53
|
+
sets ``fail_open`` is saying "keep my agent running if TrustModel is
|
|
54
|
+
unreachable". It is NOT a blanket "turn every error into an allow" —
|
|
55
|
+
so only failures that genuinely mean *we could not get a decision*
|
|
56
|
+
may be absorbed by it.
|
|
57
|
+
|
|
58
|
+
Availability (fail_mode may apply):
|
|
59
|
+
* no ``status_code`` at all — connect error, timeout, or a 2xx
|
|
60
|
+
whose body would not parse. Nothing was decided.
|
|
61
|
+
* 5xx — the service accepted the request and broke.
|
|
62
|
+
|
|
63
|
+
Everything else propagates, deliberately:
|
|
64
|
+
* 400 / 404 / 422 — the request itself is wrong. Allowing it would
|
|
65
|
+
convert a caller's bug into a permit.
|
|
66
|
+
* 401 / 403 — bad or expired credentials. A misconfigured key must
|
|
67
|
+
never silently become "allow everything"; that is the one failure
|
|
68
|
+
mode where failing open is most dangerous and least expected.
|
|
69
|
+
* 429 — rate limited. Treating this as availability would let a
|
|
70
|
+
caller exceed their limit *by* exceeding it.
|
|
71
|
+
* 3xx — unexpected here (redirects are followed by default), so it
|
|
72
|
+
is not evidence the service was unavailable.
|
|
73
|
+
|
|
74
|
+
Consulted only on the Aurora path. Edge deliberately falls back on
|
|
75
|
+
*any* transport error, including 4xx — see
|
|
76
|
+
``test_edge_400_falls_back_to_aurora``; the SDK does not interpret
|
|
77
|
+
Edge's 4xx semantics, and TRUS-2159 did not change that.
|
|
78
|
+
"""
|
|
79
|
+
if self.status_code is None:
|
|
80
|
+
return True
|
|
81
|
+
return 500 <= self.status_code <= 599
|
|
82
|
+
|
|
48
83
|
|
|
49
84
|
class RuntimeTransport(ABC):
|
|
50
85
|
"""Abstract HTTP transport for runtime decide() calls."""
|
|
@@ -209,8 +209,21 @@ class GuardrailsEndpoint:
|
|
|
209
209
|
Raises:
|
|
210
210
|
ValidationError: tool is empty / agent_id missing when
|
|
211
211
|
Aurora is the only path.
|
|
212
|
-
EdgeUnreachableError:
|
|
213
|
-
|
|
212
|
+
EdgeUnreachableError: no transport could produce a decision
|
|
213
|
+
AND ``fail_mode == "closed"``. Since TRUS-2159 this covers
|
|
214
|
+
an Aurora *availability* failure (connect, timeout, 5xx,
|
|
215
|
+
unparseable body) as well as an Edge one — previously an
|
|
216
|
+
Aurora failure escaped as an internal transport error and
|
|
217
|
+
``fail_mode`` never applied to it.
|
|
218
|
+
|
|
219
|
+
Note:
|
|
220
|
+
``fail_mode`` governs availability only. A 4xx from Aurora —
|
|
221
|
+
400/404/422 (bad request), 401/403 (bad credentials) or 429
|
|
222
|
+
(rate limited) — always propagates, even under
|
|
223
|
+
``fail_mode="open"``. Absorbing those would turn a caller's
|
|
224
|
+
bug or a misconfigured key into a silent allow. They surface
|
|
225
|
+
as an internal transport error, which is not currently part
|
|
226
|
+
of the public exception surface.
|
|
214
227
|
"""
|
|
215
228
|
if not tool:
|
|
216
229
|
raise ValidationError("guardrails.decide(): `tool` is required")
|
|
@@ -251,6 +264,7 @@ class GuardrailsEndpoint:
|
|
|
251
264
|
|
|
252
265
|
# ── Edge primary ────────────────────────────────────────────
|
|
253
266
|
last_edge_error: Optional[BaseException] = None
|
|
267
|
+
last_aurora_error: Optional[TransportError] = None
|
|
254
268
|
if edge is not None:
|
|
255
269
|
try:
|
|
256
270
|
body = _build_edge_body(
|
|
@@ -293,31 +307,65 @@ class GuardrailsEndpoint:
|
|
|
293
307
|
agent_id=agent_id,
|
|
294
308
|
policy_name=resolved_policy_name,
|
|
295
309
|
)
|
|
296
|
-
|
|
297
|
-
|
|
310
|
+
try:
|
|
311
|
+
raw = aurora.post("/api/v1/guardrails/check", body, timeout=self._client._timeout)
|
|
312
|
+
except TransportError as exc:
|
|
313
|
+
# TRUS-2159: before this, the Aurora call was unguarded, so a
|
|
314
|
+
# TransportError propagated and the fail_mode block below was
|
|
315
|
+
# unreachable whenever Aurora was configured — which is always,
|
|
316
|
+
# for a Direct HTTP agent with no edge_url. A caller who asked
|
|
317
|
+
# for fail_open got an exception instead of the documented allow.
|
|
318
|
+
#
|
|
319
|
+
# Only availability failures are absorbed. A 4xx/401/403/429 is
|
|
320
|
+
# re-raised: turning a malformed request or a bad credential into
|
|
321
|
+
# an allow would be a far worse bug than the one being fixed.
|
|
322
|
+
if not exc.is_availability_failure:
|
|
323
|
+
raise
|
|
324
|
+
logger.info(
|
|
325
|
+
"trustmodel.guardrails.aurora_failed",
|
|
326
|
+
extra={"reason": str(exc), "status_code": exc.status_code},
|
|
327
|
+
)
|
|
328
|
+
last_aurora_error = exc
|
|
329
|
+
else:
|
|
330
|
+
return _decision_from_aurora(raw)
|
|
298
331
|
|
|
299
332
|
# ── Neither succeeded: fail_mode decides ────────────────────
|
|
333
|
+
# TRUS-2159: reachable now for an Aurora availability failure too, not
|
|
334
|
+
# only when Aurora was never configured.
|
|
335
|
+
last_error = last_aurora_error or last_edge_error
|
|
336
|
+
# Which transport we got furthest with — the fail-open Decision reports
|
|
337
|
+
# it so a ``stale=True`` allow stays diagnosable.
|
|
338
|
+
attempted = "aurora" if last_aurora_error is not None else "edge"
|
|
339
|
+
if last_edge_error is not None and last_aurora_error is not None:
|
|
340
|
+
unreachable = "Edge and Aurora unreachable"
|
|
341
|
+
elif last_aurora_error is not None:
|
|
342
|
+
unreachable = "Aurora unreachable"
|
|
343
|
+
elif aurora is None:
|
|
344
|
+
# Preserved wording: pinned by test_fail_closed_edge_down_no_aurora_raises.
|
|
345
|
+
unreachable = "Edge unreachable and no Aurora fallback configured"
|
|
346
|
+
else:
|
|
347
|
+
unreachable = "Edge unreachable"
|
|
348
|
+
|
|
300
349
|
if self._client.fail_mode == "open":
|
|
301
350
|
logger.warning(
|
|
302
351
|
"trustmodel.guardrails.fail_open",
|
|
303
|
-
extra={
|
|
352
|
+
extra={
|
|
353
|
+
"last_error": str(last_error) if last_error else None,
|
|
354
|
+
"transport": attempted,
|
|
355
|
+
},
|
|
304
356
|
)
|
|
305
357
|
return Decision(
|
|
306
358
|
verdict="allow",
|
|
307
359
|
rule_id="fail_open",
|
|
308
360
|
reason=(
|
|
309
|
-
"
|
|
310
|
-
+ (f": {last_edge_error}" if last_edge_error else "")
|
|
361
|
+
f"{unreachable} and fail_mode=open" + (f": {last_error}" if last_error else "")
|
|
311
362
|
),
|
|
312
|
-
source=
|
|
363
|
+
source=attempted,
|
|
313
364
|
stale=True,
|
|
314
365
|
)
|
|
315
366
|
raise EdgeUnreachableError(
|
|
316
|
-
(
|
|
317
|
-
|
|
318
|
-
"(fail_mode=closed)" + (f": {last_edge_error}" if last_edge_error else "")
|
|
319
|
-
),
|
|
320
|
-
last_error=last_edge_error if isinstance(last_edge_error, Exception) else None,
|
|
367
|
+
(f"{unreachable} (fail_mode=closed)" + (f": {last_error}" if last_error else "")),
|
|
368
|
+
last_error=last_error if isinstance(last_error, Exception) else None,
|
|
321
369
|
)
|
|
322
370
|
|
|
323
371
|
|
|
@@ -371,6 +419,14 @@ def _build_aurora_body(
|
|
|
371
419
|
# ── response normalizers ──────────────────────────────────────────────
|
|
372
420
|
|
|
373
421
|
|
|
422
|
+
# TRUS-2158: an ``audit`` rule permits the call and records it. Edge sends it
|
|
423
|
+
# as ``verdict: "audit"``; Aurora sends ``decision: "allow"`` plus
|
|
424
|
+
# ``policy_action: "audit"`` (older Aurora: only ``evidence.rails_action``).
|
|
425
|
+
# Both normalize to ``verdict="allow", policy_action="audit"`` so ``verdict``
|
|
426
|
+
# stays in its documented allow/deny/redact vocabulary.
|
|
427
|
+
_AUDIT = "audit"
|
|
428
|
+
|
|
429
|
+
|
|
374
430
|
def _decision_from_edge(raw: Dict[str, Any]) -> Decision:
|
|
375
431
|
redactions = raw.get("redactions") or []
|
|
376
432
|
if not isinstance(redactions, list):
|
|
@@ -378,8 +434,13 @@ def _decision_from_edge(raw: Dict[str, Any]) -> Decision:
|
|
|
378
434
|
framework_tags = raw.get("matched_framework_tags") or []
|
|
379
435
|
if not isinstance(framework_tags, list):
|
|
380
436
|
framework_tags = []
|
|
437
|
+
verdict = str(raw.get("verdict", ""))
|
|
438
|
+
policy_action = verdict
|
|
439
|
+
if verdict == _AUDIT:
|
|
440
|
+
verdict = "allow"
|
|
381
441
|
return Decision(
|
|
382
|
-
verdict=
|
|
442
|
+
verdict=verdict,
|
|
443
|
+
policy_action=policy_action,
|
|
383
444
|
rule_id=str(raw.get("rule_id", "") or ""),
|
|
384
445
|
reason=str(raw.get("reason", "") or ""),
|
|
385
446
|
redactions=[str(p) for p in redactions],
|
|
@@ -406,8 +467,14 @@ def _decision_from_aurora(raw: Dict[str, Any]) -> Decision:
|
|
|
406
467
|
policy_id = None
|
|
407
468
|
trust_score = raw.get("trust_score")
|
|
408
469
|
trust_score_int = int(trust_score) if isinstance(trust_score, (int, float)) else None
|
|
470
|
+
verdict = str(raw.get("decision", ""))
|
|
471
|
+
policy_action = str(raw.get("policy_action", "") or "")
|
|
472
|
+
if not policy_action:
|
|
473
|
+
audited = verdict == "allow" and evidence.get("rails_action") == _AUDIT
|
|
474
|
+
policy_action = _AUDIT if audited else verdict
|
|
409
475
|
return Decision(
|
|
410
|
-
verdict=
|
|
476
|
+
verdict=verdict,
|
|
477
|
+
policy_action=policy_action,
|
|
411
478
|
rule_id=str(evidence.get("rule_id", "") or ""),
|
|
412
479
|
reason=str(raw.get("reason", "") or ""),
|
|
413
480
|
redactions=redactions,
|
|
@@ -43,6 +43,13 @@ class Decision:
|
|
|
43
43
|
stale: ``True`` only when Edge returned a stale-policy fallback
|
|
44
44
|
verdict (Aurora is always ``False``).
|
|
45
45
|
source: ``"edge"`` or ``"aurora"`` — which transport answered.
|
|
46
|
+
policy_action: The governance action the matched rule asked for:
|
|
47
|
+
``"allow"``, ``"deny"``, ``"redact"``, or ``"audit"``. Equal to
|
|
48
|
+
``verdict`` except for an ``audit`` rule, where ``verdict`` is
|
|
49
|
+
``"allow"`` (the call is permitted) and ``policy_action`` is
|
|
50
|
+
``"audit"`` (it was recorded as a governance event). Enforce on
|
|
51
|
+
``verdict``; read this to know the call was audited. Defaults
|
|
52
|
+
to ``verdict`` when not supplied.
|
|
46
53
|
"""
|
|
47
54
|
|
|
48
55
|
verdict: str
|
|
@@ -56,6 +63,11 @@ class Decision:
|
|
|
56
63
|
trust_score: int | None = None
|
|
57
64
|
stale: bool = False
|
|
58
65
|
source: str = "edge"
|
|
66
|
+
policy_action: str = ""
|
|
67
|
+
|
|
68
|
+
def __post_init__(self) -> None:
|
|
69
|
+
if not self.policy_action:
|
|
70
|
+
object.__setattr__(self, "policy_action", self.verdict)
|
|
59
71
|
|
|
60
72
|
def applied_args(self, args: Mapping[str, Any]) -> dict[str, Any]:
|
|
61
73
|
"""Return a deep copy of ``args`` with redacted JSON paths nulled.
|
|
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
|
|
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
|