Skip to main content

Module util

Module util 

Source
Expand description

Shared helpers for codec validation, diagnostics, and preservation metadata.

Constants§

PRESERVATION_METADATA_KEY
Public alias for the embedded preservation metadata key.
SWITCHYARD_METADATA_KEY
Metadata key used to embed exact preserved payloads in provider JSON.

Functions§

capture_request_preservation
Captures an exact source request body according to preservation policy.
capture_response_preservation
Captures an exact source response body according to preservation policy.
compact_text_blocks
Joins non-empty text fragments with a caller-provided separator.
embed_preservation
Embeds preservation metadata into a translated wire body when requested.
exact_preserved_request
Returns an exact preserved request for the target format when available.
exact_preserved_response
Returns an exact preserved response for the target format when available.
extract_preservation
Extracts embedded preservation metadata from a provider wire body.
is_truthy_string
Returns a non-empty string when the value is string-like enough to preserve.
json_string
Serializes JSON values into provider argument strings.
normalize_anthropic_tool_use_ids
Normalizes Anthropic tool-use IDs while keeping tool_use/tool_result pairs aligned.
object
Reads a JSON object or returns a typed translation error at the given path.
prepare_request_for_target
Applies a selected target model and optionally prepends its system prompt.
push_lossy
Applies the lossy-conversion policy and records diagnostics when configured.
push_unknown_field
Applies the unknown-field policy and records diagnostics when configured.
sanitize_anthropic_tool_use_id
Converts an ID into a reversible Anthropic-safe representation.
stable_id
Generates a stable, human-readable ID from a prefix and counter.
string_value
Converts JSON scalars to Python-compatible string values where providers do so.
validate_request_capabilities
Checks a request against declared target capabilities.