← Blog

Anthropic Document Source Types Form a Fixed API Union

Parminder Singh
Parminder Singh··5 min read
Summarize with AI

Anthropic document blocks accept a fixed schema union of source variants: base64 PDF; plain text; content blocks; URL PDF; and Files API references. That union describes API syntax, not a configurable Anthropic security allowlist. A gateway can first validate the selected variant against the current Messages schema, then apply enterprise route policy to URLs and file IDs; media types and size; classification and provenance.

AI Security Solutionsai-securityllm-securitypolicy-enforcementzero-trustarchitectureaudit
Anthropic Document Source Types Form a Fixed API Union

Anthropic's Messages schema defines five source variants for a document content block. They are base64 PDF; plain text; content; URL PDF; and Files API reference. The nested type discriminator chooses one shape from that fixed union.

The list defines API syntax rather than a configurable Anthropic security feature. Calling it an allowlist can blur the ownership line. Enterprise policy begins after schema validation, when the gateway decides which valid source variant this route may send.

TL;DR

  • Validate document.source against Anthropic's current five-variant schema union.
  • Describe that union as a fixed API contract, not a user-configurable provider security allowlist.
  • Add a separate route allowlist for source variants and URL origins; file ownership and media types; size and classification.
  • Preserve the selected variant and policy outcome in audit evidence without logging full document bodies.

The API union has five distinct variants

The Anthropic Messages API reference lists Base64PDFSource; PlainTextSource; ContentBlockSource; URLPDFSource; and FileDocumentSource. Their discriminator values are base64; text; content; url; and file.

Each variant has its own required members. Base64 uses data with media_type: application/pdf, while plain text pairs data with media_type: text/plain. Content accepts a string or supported text and image blocks. The URL variant carries its remote reference, and the file variant carries a file_id.

A validator should use the nested type member to select one branch and require its fields. Members borrowed from another variant must fail validation. A url source with embedded data, or a file source with an arbitrary URL, signals serializer drift or an attempt to smuggle unchecked members through permissive JSON handling.

Pin validation to the provider API version and adapter release. The LLM API parameter allowlisting pattern applies to this nested union as much as to top-level fields.

Schema acceptance grants no enterprise authorization

A fixed union tells developers what Anthropic accepts. It cannot express that the finance route permits a Files API reference but forbids arbitrary URLs, or that a support route accepts plain text only after customer identifiers are redacted. Those are enterprise decisions.

Build a second allowlist keyed by authenticated route and application, with destination model and source variant. A url entry needs approved schemes and hostnames, plus redirect behavior and retrieval purpose. File references require tenant and application ownership checks before the request crosses the provider boundary. Inline base64 policy covers decoded media type and byte count, plus content classification.

My opinion is that naming the schema union a security control is dangerous documentation. It gives reviewers a green checkbox while leaving source authorization undefined.

The per-route AI policy guide gives the enterprise rule a separate owner and version. Keep that rule visually apart from the provider schema in design documents.

URL and file variants need provenance checks

Anthropic's PDF support guide documents URL and base64 paths, plus the Files API path for PDF input. Platform support varies. Some cloud surfaces accept base64 only, while first-party API routes support additional variants. Resolve platform capability before route policy so an approved enterprise variant still fails cleanly when the destination surface lacks it.

For URLs, normalize the hostname and reject userinfo. Constrain redirects and decide if query strings may carry secrets. The gateway sees the reference in the HTTP request, but Anthropic performs retrieval after receipt. A URL policy can stop an unapproved origin before dispatch. It cannot inspect bytes that Anthropic later fetches unless the application fetched and classified those bytes earlier.

For file IDs, preserve the upload principal and tenant; MIME type and digest; creation time and approved purpose in application metadata. The opaque ID alone proves little to an enterprise reviewer. A white upload card with a six-character PDF icon and a long file ID should also show the source system and tenant, not merely "attached."

Inline sources require byte-aware validation

Base64 expands binary data in the JSON body. Enforce limits on decoded bytes and the final serialized HTTP request. Validate the declared media type against the decoded file signature where practical. A string labeled application/pdf can still carry malformed or unexpected bytes.

Plain-text sources need character encoding and size, plus classification and injection handling. A content source can contain text and image blocks, so recursively apply the corresponding block validators. Avoid assuming that a content source is text-only because its top-level label sounds generic.

Run data minimization before dispatch. If the model needs two contract clauses, sending a 200-page agreement creates more disclosure and a larger context cost. Keep the original in the application's approved repository and send the smallest justified excerpt with provenance.

Prompt injection protection covers the wider treatment of instructions embedded inside user uploads and fetched documents. Source-type validation only establishes shape.

Audit records should name both decisions

Write one result for provider-schema validation and another for enterprise route policy. The first records API version and source discriminator, plus required-member check and adapter version. The second records identity and route; source owner and classification; size and destination; policy version and transformation; and final outcome.

For URL sources, store a normalized origin and a protected full-reference digest. Query strings can contain tokens or customer identifiers, so avoid copying them into general logs. For file IDs, store a digest or controlled reference plus upload provenance. For inline data, record decoded byte count and detected media type, plus classification and payload digest.

The AI audit log schema can carry common fields. Keep document bodies in an access-controlled evidence store only when an approved incident or compliance purpose requires them.

Contract tests should cover every branch

Build one minimal valid fixture for each of the five variants. Send them through the same serializer and HTTP gateway used in production. Confirm the final JSON selects exactly one union branch and carries only its allowed members.

Then cross the branches deliberately. Put file_id under url; attach media_type: text/plain to a base64 PDF branch; omit required data; add an unknown source type; and place an unsupported nested block inside content. The local validator should stop each malformed request before provider dispatch.

For policy tests, allow file on one route and deny it on another. Use an approved URL origin; a redirect to an unapproved origin; a file ID owned by another synthetic tenant; an oversized inline payload; and plain text containing a fake secret marker. Confirm provider-schema success never bypasses route policy.

DeepInspect

DeepInspect can validate the fixed Anthropic document-source union and enforce a separate route-specific source policy on authenticated user or agent HTTP requests deliberately sent through its proxy. It can reject malformed variants; unapproved URL origins; mismatched media types; oversized inline data; or unauthorized file references before the Messages request reaches Anthropic.

The application owns file-upload provenance and any prefetch inspection of remote document bytes. Anthropic owns retrieval and processing after an accepted request arrives. Direct provider calls and upload traffic that bypasses the proxy sit outside this decision record.

Book a technical deep dive at deepinspect.ai.

Frequently asked questions

Is Anthropic's document source union a security allowlist?

No. It is the fixed set of source shapes accepted by the API schema. Organizations can build a route-specific security allowlist on top of it, but Anthropic does not present the union itself as a configurable enterprise policy.

Which source types does a document block accept?

The current Messages reference lists base64; text; content; url; and file, each with a distinct schema. Platform availability can narrow which variants work on a specific destination.

Can a valid URL source be trusted automatically?

No. Schema validation confirms that it is a URL-shaped source. Enterprise policy still needs origin and redirect; purpose and classification; and retrieval-boundary decisions before dispatch.

Should the gateway log document data?

General audit logs should carry metadata and classifications, plus digests and controlled references. Store full bodies only in a protected evidence system with an approved purpose, access policy, and expiry.