cadrumo.adapters.outbound.llm.models module¶
Strict Pydantic models for the outbound LLM adapter.
This module is the canonical owner of request, response, provider, cache, usage, prompt, and validation record types. Consumers import these records directly from this defining module; the sibling package initializer is inert.
- class MultimodalImageInput(**data)[source]¶
Bases:
BaseModelOne on-host-prepared image attached to a multimodal LLM request.
Transient and in-memory only. Carries the base64-encoded image bytes the provider adapter forwards to a vision model and the content address (an attachment-store SHA-256) that
LLMCachefolds intoCacheKey. The base64 payload is never persisted – only its content address enters the cache key (sensitive-financial-data-secure-storage-only).media_typehas no default on purpose. A local runtime sniffs the bytes, but a cloud provider validates the declared type against them and refuses the pair when they disagree – so a defaulted media type is exactly how a JPEG attachment gets sent as a PNG and the read fails or, worse, is silently misinterpreted. The producer knows what it built; it declares it.- Parameters:
data (Any)
- content_sha256: ContentDigest¶
- base64_data: str¶
- media_type: ImageMediaType¶
- classmethod from_base64(base64_data, media_type)[source]¶
Build one input from encoded image bytes and their known media type.
The single place the content address is derived, so a producer cannot pair one image’s payload with another’s digest. The address is the SHA-256 of the DECODED bytes, matching the attachment store’s own content addressing.
- Parameters:
base64_data (
str) – Base64-encoded image bytes.media_type (
ImageMediaType) – The type those bytes actually are – from the producer’s own knowledge (the page rasteriser only ever emits PNG) or fromdetect_image_media_type()over the raw bytes.
- Return type:
- Returns:
The transient multimodal input carrying all three fields.
- class LLMRequest(**data)[source]¶
Bases:
BaseModelUser-facing completion request accepted by
LLMClient.Provider and model override fields select
LLMProvidervalues for one call, andimagescarries transientMultimodalImageInputpayloads for local vision flows.evidence_deriveddefaults toFalsebecause most requests carry no taxpayer content at all – a column-role mapping reads spreadsheet headers, a corpus measurement reads a public synthetic document. The fail-closed default lives one level up, at the evidence READERS, which mark every request they build unless the caller names a public corpus: an unmarked request is therefore a deliberate statement about the content, not an omission.consent_tokenenters neither the cache key nor any persisted record; it exists only between its minting site and the dispatch point.- Parameters:
data (Any)
- prompt: str¶
- system: str | None¶
- max_tokens: int | None¶
- temperature: float | None¶
- language: str | None¶
- cache_key: str | None¶
- provider_override: LLMProvider | None¶
- model_override: str | None¶
- images: tuple[MultimodalImageInput, ...]¶
- evidence_derived: bool¶
- consent_token: EvidenceConsentToken | None¶
- classmethod validate_prompt(cls, value)[source]¶
Ensure prompts are not empty or whitespace-only.
- Raises:
LLMValidationError – When the
prompt is blank after trimming. –
- Return type:
- Parameters:
value (str)
- class LLMResponse(**data)[source]¶
Bases:
BaseModelCompletion response returned by
complete().Responses are persisted inside
CachedEntryrecords and converted intoUsageRecordvalues for cost tracking.- Parameters:
data (Any)
- text: str¶
- provider: LLMProvider¶
- model: str¶
- input_tokens: int¶
- output_tokens: int¶
- cost_estimate_usd: Decimal | None¶
- cache_hit: bool¶
- created_at: datetime¶
- request_id: str¶
- class PromptDefinition(**data)[source]¶
Bases:
BaseModelPrompt metadata stored by
PromptRegistry.- Parameters:
- id: str¶
- version: int¶
- template: str¶
- expected_output_schema: type[BaseModel] | None¶
- description: str¶
- class PromptRegistry(**data)[source]¶
Bases:
BaseModelRegistry of versioned
PromptDefinitionvalues.- Parameters:
data (Any)
- definitions: dict[str, PromptDefinition]¶
- register(definition)[source]¶
Add or replace a prompt definition.
- Return type:
- Parameters:
definition (PromptDefinition)
- get(prompt_id, version=None)[source]¶
Return a
PromptDefinitionby id and optional version.- Return type:
- Parameters:
- classmethod seeded()[source]¶
Return a default
PromptRegistry.- Return type:
- class CachedEntry(**data)[source]¶
Bases:
BaseModelEncrypted cache record persisted by
LLMCache.- Parameters:
data (Any)
- provider: LLMProvider¶
- model: str¶
- prompt_hash: str¶
- args_hash: str¶
- response: LLMResponse¶
- created_at: datetime¶
- class UsageRecord(**data)[source]¶
Bases:
BaseModelAppend-only usage record persisted by
UsageRecorder.- Parameters:
data (Any)
- prompt_id: str¶
- caller: str¶
- text: str¶
- provider: LLMProvider¶
- model: str¶
- input_tokens: int¶
- output_tokens: int¶
- cost_estimate_usd: Decimal | None¶
- cache_hit: bool¶
- created_at: datetime¶
- request_id: str¶
- class CacheKey(**data)[source]¶
Bases:
BaseModelDerived cache key used by
LLMCache.- Parameters:
data (Any)
- provider: LLMProvider¶
- model: str¶
- prompt_hash: str¶
- args_hash: str¶