judgevet.adapters.outbound.request_body

Status: draft.

judgevet.adapters.outbound.request_body

Prepare opt-in redacted state immediately before request serialization.

Redaction sees a deep copy of ordinary JSON state. The immutable serialized body is reused across retries. The unconfigured path retains HTTPX JSON handling. Wire payload fields follow https://docs.typesafe.ai/api.

Examples:

from judgevet.adapters.outbound.request_body import prepare_body

payload = {"state": "synthetic", "questions": {}, "model": "jev-latest"}
assert prepare_body(payload, None) is payload
See Also

AdapterOptions

Bases: GatewayOptions

Extend typed constructor options without changing existing parameters.

Attributes:

Name Type Description
redactor StateRedactor | None

Caller-owned synchronous state transformation.

Examples:

options: AdapterOptions = {"redactor": None}
assert configured_redactor(options) is None

configured_redactor(options)

Validate constructor extensions and select explicit redaction.

Parameters:

Name Type Description Default
options AdapterOptions

Typed gateway and redactor keywords from an HTTP constructor.

required

Returns:

Type Description
StateRedactor | None

The optional callback; None leaves the existing path unchanged.

Raises:

Type Description
TypeError

If an untyped caller supplies an unknown keyword.

prepare_body(payload, redactor)

Transform a copied state and snapshot bytes before entering retry handling.

Parameters:

Name Type Description Default
payload dict[str, Any]

Built state, questions and model fields.

required
redactor StateRedactor | None

Optional trusted caller transformation.

required

Returns:

Type Description
dict[str, Any] | bytes

Existing JSON payload when unconfigured, otherwise immutable UTF-8 bytes.

Raises:

Type Description
TypeError

If transformed state has an unsupported root or is not JSON data.

ValueError

If transformed data cannot be encoded as finite JSON.

Exception

If copying state or the caller's transformation fails.