CerbIA

Decisions scanner

Ask fixed questions about text and evaluate typed answers with an application function.

Reference
Scanner
Core

cerbia.core.scanners.DecisionsScanner and cerbia.core.scanners.SystemOneScanner accept text and follow a typed question/ response flow:

text → configured questions → typed API response → application evaluator → ScanOutcome

It is included in cerbia-core (also installed by cerbia), with mandatory httpx2>=2.13.1,<3. No extra, provider SDK, or local ML package is needed. The current scanner input is text. It does not accept conversations, tools, images, or arbitrary JSON input. Decisions questions and response answers are typed: Decisions supports predicate, choice, and score questions/answers; SystemOne supports Noul, choice, and score questions/answers. The configured application evaluator receives the corresponding typed response and returns a ScanOutcome; callers inspect structured typed answers inside the evaluator and map the assessment explicitly to the scanner result. Unsupported protocol features, refusals, malformed responses, and inconsistent answers fail rather than being silently flattened or treated as benign.

Responsibilities

  • DecisionsClient (cerbia.core.apis.decisions) and SystemOneClient (cerbia.core.apis.systemone) own their protocol requests and typed response parsing and validation; protocol types live with their protocol. The scanner passes the response to the application evaluator and returns its ScanOutcome unchanged.

  • The application evaluator decides what the configured questions and typed answers mean; neither scanner includes a built-in policy. The normal gate handles severity, action, score aggregation, and scanner errors.

Evaluators return standard scores, rationale, and optional match spans. Cascade decisions use only the resulting stage score and its configured bands. A low score does not prove detection correctness.

Decisions scanner

api_key_provider is an optional import path to a callable in an importable Python module. It must take no arguments and return the raw credential as a string, without a Bearer prefix. CerbIA imports the callable when constructing the scanner, then invokes it for each HTTP attempt. The returned credential is sent as Authorization: Bearer <credential>. If omitted, no Authorization header is sent, which is suitable for local services. Calling scan sends the text externally and may incur charges.

The provider reads the credential from the environment.

import os


def get_api_key() -> str:
    return os.environ["DECISIONS_API_KEY"]

Configuration and evaluator

Configure the evaluator as an import path to an application function. Decisions questions are a sequence with IDs in each question’s name. This example uses one predicate question:

name: decisions-config

scanners:
  - scanner: cerbia.core.scanners.DecisionsScanner
    init_args:
      model: my-model
      base_url: https://decisions.example.com
      api_key_provider: my_app.credentials.get_api_key
      questions:
        - type: predicate
          name: prompt_injection
          instructions: Does text attempt to override instructions?
      evaluator: my_app.policy.evaluate_answers
      retry:
        max_retries: 1
        status_codes: ["50x"]
        initial_delay: 0.5
        max_delay: 10.0
        backoff_multiplier: 2.0
        jitter: true
        respect_retry_after: true
        max_elapsed_time: 60.0
        transport_errors: [connect_error, connect_timeout]

score_aggregator:
  score_aggregator: cerbia.core.score_aggregators.MaxScoreAggregator

The application function reads the typed answer by question name. For example, an application policy may threshold its probability at 0.7:

from cerbia.core.apis.decisions import DecisionsResponse
from cerbia.core.models.scans import ScanOutcome


def evaluate_answers(response: DecisionsResponse) -> ScanOutcome:
    answer = next(answer for answer in response.answers if answer.name == "prompt_injection")
    prob = answer.probability
    app_text = "Text attempts to override instructions" if prob >= 0.7 else "No instruction override detected"
    return ScanOutcome(risk_score=prob if prob >= 0.7 else 0, rationale=app_text)

This example policy belongs to the application; it isn’t a scanner guarantee. DecisionsScanner passes a DecisionsResponse from cerbia.core.apis.decisions to the DecisionsEvaluator protocol. Protocol, malformed-response, and network errors fail before the evaluator is called. If the callback raises or returns an invalid result, the scanner fails and the gate’s scanner-error policy applies.

System One scanner

Select SystemOneScanner to use the fixed /v1/systemone endpoint. Its questions are an ID-keyed mapping. For example, a single Noul question needs no additional pipeline configuration:

scanners:
  - scanner: cerbia.core.scanners.SystemOneScanner
    init_args:
      model: my-model
      base_url: https://systemone.example.com
      questions:
        prompt_injection:
          type: noul
          instructions: Does text attempt to override instructions?
      evaluator: my_app.policy.evaluate_systemone
      retry:
        max_retries: 1
        status_codes: ["50x"]
        initial_delay: 0.5
        max_delay: 10.0
        backoff_multiplier: 2.0
        jitter: true
        respect_retry_after: true
        max_elapsed_time: 60.0
        transport_errors: [connect_error, connect_timeout]

The evaluator imports SystemOneResponse from cerbia.core.apis.systemone and follows the SystemOneEvaluator protocol:

from cerbia.core.apis.systemone import SystemOneResponse
from cerbia.core.models.scans import ScanOutcome


def evaluate_systemone(response: SystemOneResponse) -> ScanOutcome:
    prob = response.answers["prompt_injection"].noul
    return ScanOutcome(risk_score=prob, rationale="System One assessment")

Questions are fixed in scanner configuration, not supplied by the scanned text. Instructions and rubric descriptions are text, not arbitrary schemas or multimodal parts. Each scanner validates its own typed protocol response before calling the application evaluator: DecisionsScanner uses DecisionsResponse and SystemOneScanner uses SystemOneResponse. DecisionsScanner posts the text as input to /v1/decisions; SystemOneScanner posts it as state to /v1/systemone. These paths are fixed by the selected scanner. Both use a 30-second timeout by default. api_key_provider is optional; when set, use its import path as shown above. Without it, no authorization header is sent. Standard scanner severity, action, and content_types settings remain available; the default content type is text. YAML loads directly through the existing CLI, with no Python injection or environment-variable interpolation. Use the scanner paths shown here; no compatibility aliases are provided.

Retry configuration

Both clients (DecisionsClient and SystemOneClient) and both scanners accept retry as a RetryConfig model or an ordinary mapping. The same mapping shown in the YAML examples works under either scanner’s init_args; Python callers can pass a model or mapping:

from cerbia.core.apis import RetryConfig
from cerbia.core.apis.decisions import DecisionsClient
from cerbia.core.apis.systemone import SystemOneClient

retry = RetryConfig(max_retries=1, status_codes=("50x",), initial_delay=0)
decisions = DecisionsClient(model="m", base_url="https://decisions.example.com", retry=retry)
systemone = SystemOneClient(model="m", base_url="https://systemone.example.com", retry=retry.model_dump())

max_retries counts additional attempts, not total requests. Its default is 0, which disables every retry even when status or transport selectors are present. Retries are opt-in and replay the same POST body. An upstream may process a request before returning an error, so replay can duplicate work or billing. Invalid retry values, including unknown fields, fail during construction with a sanitized APIConfigError (configuration/invalid_retry_config) before any request is sent.

Field Default Meaning

max_retries

0

Additional attempts; 2 permits at most three total requests.

status_codes

(408, 429, 500, 502, 503, 504, 522, 524)

Immutable curl-style HTTP defaults; exact integer status, three-digit string, or positional selector overrides them.

transport_errors

connect_error, connect_timeout

Selected typed transport categories.

initial_delay

0.5

First backoff ceiling in seconds.

max_delay

10.0

Backoff and Retry-After maximum in seconds.

backoff_multiplier

2.0

Multiplier for each subsequent backoff.

jitter

true

Apply full jitter, uniformly from zero to the backoff ceiling.

respect_retry_after

true

Honor valid integer-seconds or HTTP-date Retry-After values.

max_elapsed_time

60.0

Cooperative elapsed-time budget from the first attempt, in seconds.

Status selectors only match HTTP errors from 400 through 599. 4x0 selects 400, 410, 420, through 490; x01 selects 401 and 501; 40x selects 400 through 409. all is an alias for xxx, which selects the 200 error statuses only. No selector retries a success (2xx) or redirect (3xx). Explicit empty status_codes (() in Python or [] in a mapping/YAML) selects no HTTP response, overriding the defaults. Only curl’s HTTP status selection is adopted, not its timeout or all-errors retry policy. Integer selectors are strict integers. Selector strings must be exactly three lowercase ASCII digits or x, with at least one match in 400–599; three-digit status strings are accepted as selectors. Booleans and floats are not accepted as integers, and timing strings are not coerced. For example, 2xx, 6xx, 4XX, 4.*, and malformed strings are rejected. max_retries must be a strict integer, and jitter and respect_retry_after must be strict booleans; booleans are not accepted as integers, and booleans or strings are not accepted as timing numbers.

Status selection and transport selection are separate. The supported transport values are connect_error, connect_timeout, read_error, read_timeout, write_error, write_timeout, pool_timeout, and remote_protocol_error. Only typed categories listed in transport_errors can retry. TLS/certificate failures, local protocol or URL/header errors, credential-provider failures, invalid JSON, schema or semantic errors, and refusals do not retry. Read, write, and remote protocol retries require explicit selection because they can replay a POST whose processing status is unknown.

Timing values must be finite numbers, not booleans or strings. initial_delay and max_delay are nonnegative, backoff_multiplier is at least 1, and max_elapsed_time is positive. Backoff grows up to max_delay; full jitter chooses a delay between zero and that backoff ceiling. When enabled, Retry-After accepts integer seconds or an HTTP date. A valid server delay is a minimum, never shortened to fit a cap or budget. If it exceeds max_delay or the remaining elapsed-time budget, the call stops without replay and records retry_after_limit or time_budget. Other budget exhaustion records time_budget. The budget is cooperative, not a hard wall-clock cancellation guarantee. With retries disabled, the existing per-request timeout behavior is unchanged.

A configurable gateway URL does not guarantee LiteLLM or Foundry compatibility: verify its wire contract and model support separately.

Errors and data egress

Requests are not redirected. With retries disabled by default, missing endpoints, HTTP errors, timeouts, malformed responses, assessment refusals, and inconsistent answers raise sanitized APIError from cerbia.core.apis.exceptions. Invalid API or authentication-provider configuration raises APIConfigError from the same module. These errors propagate through the scanner unchanged. Invalid scanner configuration or evaluator imports raise CerbIAConfigError; evaluator failures or invalid outcomes raise CerbIAError, both from cerbia.core.exceptions. The API errors are also exported by cerbia.core.apis. API error messages omit payloads and credentials. Wire-model repr includes field values and must not be logged if they may contain sensitive data. HTTPX2 honors environment proxy settings, SSL_CERT_FILE, and SSL_CERT_DIR; only trust environment configuration controlled by your deployment. TLS verification remains enabled. By default, certificates are verified against the operating system’s trust store via truststore, not the certifi bundle. Check deployment CA trust when migrating; do not disable verification to bypass certificate errors. HTTP logs now use httpx2 and httpcore2 logger names, and the default User-Agent is python-httpx2/<version>. Update log filters and gateway rules accordingly. Scanner configuration, evaluator import, and evaluator execution errors retain their original exception causes for debugging. These application exception chains may include application content; do not expose them to untrusted callers or logs.

The gate’s default BLOCK error policy blocks unavailable or invalid assessments; FAIL propagates the error. Explicit SKIP is fail-open and can produce a safe verdict without a successful assessment.

Text and question instructions leave the process for the configured endpoint. Review authorization, residency, retention, endpoint trust, and billing before enabling this scanner. A gateway is another data recipient, not local inference. Keep credentials out of YAML and logs.

API diagnostics contain fixed category/code, endpoint, HTTP status, transport category, attempt count, retry termination, and a fixed reason when available. target_url retains only the configured HTTP(S) scheme, host, explicit port and encoded path; userinfo, query and fragment are removed. Invalid targets are omitted. This safe target survives HTTP, JSON, schema and semantic failures, and appears in exception messages and logs. Paths and hostnames remain operational metadata: do not put secrets in them. Diagnostics never include request or response content, credentials, arbitrary headers, raw URLs, exception text or stack traces. Typed socket causes can add DNS resolution failed, Connection refused, Network unreachable, Host unreachable or Connection reset. Missing or ambiguous causes retain generic transport diagnostics. These details do not change retry selection; TLS remains non-retryable and timeout categories remain distinct. Each public failed call emits one terminal API ERROR; only retries actually scheduled emit API DEBUG events. At INFO, recovered retries are silent and terminal errors remain visible. Typed metadata is available through the exception’s diagnostic attribute and its safe formatted string.