Expand description
Offline preflight for canonical user attachments and rich tool results.
This is a model and transport gate, not a model-name heuristic. Nothing here fetches a catalog, reads an attachment path, or contacts a provider. Call again on every outgoing history (including resume/model switches). Errors are static: neither payloads, titles, MIME strings nor model IDs from untrusted messages are interpolated into diagnostics.
Constants§
- MAX_
ATTACHMENTS_ PER_ MESSAGE - Shared with attachment loaders; nested tool media counts toward this limit.
- MAX_
BROKER_ PROXY_ BYTES - Keep the broker’s existing bound authoritative; never raise it for media.
- MAX_
HISTORY_ ENCODED_ BYTES - Encoded attachment blocks across the complete outgoing history.
- MAX_
IMAGE_ BYTES - 3.5 MiB, matching the read tool’s raw image bound.
- MAX_
PDF_ BYTES - MAX_
TEXT_ DOCUMENT_ BYTES - UTF-8 bytes, not Unicode scalar values.
Functions§
- validate_
history_ for_ request - Original admission is separate from strict projected-wire validation. Native Anthropic defers only the aggregate budget to synchronous original replay.
- validate_
messages - Validate canonical top-level user image/document blocks and media inside
user
tool_result.contentarrays. Non-media tool inputs are not traversed: a JSON object supplied as tool arguments is data, not a content block. - validate_
tool_ blocks - Validate one tool’s rich output before committing it to a tool_result. Callers can replace Err with a plain-text tool error; no offending bytes need enter history. The outgoing full-history check remains mandatory, since sibling tool results share one message count/broker/history budget.