Skip to main content

Errors

from jes import (JesError, ConfigError, PolicyError, PolicyExecutionError,
RedactionError, BackendError, DeadlineExceeded)

The same classes are also importable from jes.errors. Every one of them derives from JesError, so except JesError catches any jes error.

Messages carry metadata only. Checked text and provider response bodies are never put into an exception, so an error is always safe to log.

Problems with input size, content, or context are findings, not exceptions. See Failures and limits.

JesError​

The base class for jes errors.

ConfigError​

A hook payload, config file, or environment setting is invalid. The agent hooks raise it. The Python library doesn't.

PolicyError​

A policy or guard configuration is invalid. It is mostly raised when a Guard or a policy is built. Examples:

  • duplicate policy names, or a name or label that isn't an identifier;
  • a judgment without threshold=, or a judgment with no model;
  • a Limits field that isn't a positive integer;
  • questions that leave no room for the text;
  • a Guard given an async-only backend;
  • pii with PERSON but without Presidio and a spaCy model;
  • Redactions.dumps without jes[crypto].

PolicyExecutionError​

A custom policy broke its contract while a check ran. Examples: the policy raised, returned the wrong type, returned invalid edits, a hit or span outside the text, an invalid label, or an unknown action. It always raises, whatever on_backend_error says, because it signals a bug in a policy.

RedactionError​

A redaction store, scope, or saved blob failed a check. Examples: the redactions= you passed differs from the store on a prompt= or question= result, a Redactions argument is out of range, or a blob fails to load. See Redactions.

BackendError​

BackendError(backend: str, reason: str, *, status_code: int | None = None,
question_ids: Iterable[str] = ())

A backend request or reply failed. The attributes are backend, reason, status_code, and question_ids. reason says why:

reasonRaised by
client_setup_failed, timeout, malformed_response, unauthorized, rate_limited, upstream_error, rejected, connection_error, malformed_answerTypeSafe. See the table.
malformed_replyThe guard, when a backend returns something other than a Reply, or a reply without an answer it was asked for
malformed_answerThe guard, when an answer doesn't fit its question
unexpected_errorThe guard, when a backend raises an exception that isn't a BackendError
no_answerFakeBackend, for a question it has no answer for
deadline_exceededDeadlineExceeded

A custom backend raises it for its own failures, with its own reasons.

How a check treats a backend error depends on the guard's on_backend_error:

on_backend_errorEffect
"raise" (default)The check raises the BackendError
"block"A blocking backend_error finding
"allow"A flag backend_error finding

With "block" or "allow", the result is incomplete, so ok is false either way.

DeadlineExceeded​

DeadlineExceeded(backend: str, *, question_ids: Iterable[str] = ())

A subclass of BackendError, with reason deadline_exceeded. The check reached the guard's deadline_s before its backend requests finished. It follows on_backend_error like any backend error, with the finding label deadline_exceeded.