Skip to content

Attachments

LLMStep(attachments="column") sends a row's documents (PDFs today) to the model alongside the prompt, instead of asking you to extract their text first. The model reads the file; accrue just carries the bytes.

from accrue import Pipeline, LLMStep

pipeline = Pipeline([
    LLMStep("read_contract",
        fields={
            "counterparty": "Name of the counterparty",
            "term_months": {"prompt": "Contract term in months", "type": "Number"},
        },
        model="claude-sonnet-5-5",
        attachments="documents",
    ),
])

result = pipeline.run([
    {"deal": "Acme", "documents": "contracts/acme.pdf"},
    {"deal": "Beta", "documents": ["contracts/beta.pdf", "contracts/beta-amendment.pdf"]},
])

The named column is removed from the <row_data> JSON in the prompt and rendered as provider document blocks ahead of the user text. Every other column still reaches the prompt as usual.

What a cell can hold

Cell value Becomes
"path/to/file.pdf" or a pathlib.Path one Document read from disk
b"%PDF-..." one Document with media_type="application/pdf"
Document(...) itself
a list/tuple/numpy array of any of the above one Document each, in order
None, NaN, pd.NA, "", [] no attachments — a plain text prompt

Anything else raises StepError naming the offending type, as does a path that cannot be read. A row that lacks the column altogether also raises, so a misspelt column name fails every row before any call instead of quietly sending prompts without their documents. On the batch path these are per-row errors raised before anything is submitted; the rest of the batch still goes out.

Document

from accrue import Document

doc = Document.from_path("report.pdf")              # title defaults to "report.pdf"
doc = Document.from_path("report.pdf", title="Q3")  # media type guessed via mimetypes
doc = Document(data=pdf_bytes, media_type="application/pdf", title="Q3")

doc.sha256   # hex digest of the bytes — the cache identity

Frozen dataclass, and its repr prints the title, media type, and byte count — never the bytes.

Provider support

Anthropic OpenAI Gemini OpenAI-compatible (base_url)
Realtime Yes Yes Yes No
Batch (batch=True) Yes Yes No batch path, runs realtime No
Media types Passed through PDF PDF None
Sent as base64 document block base64 input_file (realtime) or file (batch) part inline application/pdf part
Title Document title Filename A text line before the document

The provider is picked from the model name, so the same pipeline runs on each by changing model= (provider_kwargs, if you set any, are specific to a provider).

What can't be sent fails the row. On OpenAI and Gemini, accrue checks the documents before any call and gives the row a StepError naming the row, model and reason. No call is made for that row, realtime or batch, and the other rows carry on. It refuses:

  • a media type other than application/pdf, or an empty file
  • a base_url client, or an OPENAI_BASE_URL that isn't OpenAI's, because gateways differ in how they handle files
  • an OpenAI model that takes text only, such as gpt-oss-120b: OpenAI sends a PDF's text and page images to the model, so it needs one that accepts images
  • a Gemini speech or embedding model

The lists of models cover the ones known to refuse. Any other model, or a file that isn't really a PDF, is refused by the provider, if it refuses it.

On GPT-5.6 and later, OpenAI renders PDF pages at high detail by default on the realtime path. Batch requests have no detail setting, so input tokens can differ between the two.

Caching

The cache key hashes the document bytes, not the path. The same PDF under two filenames is one cache entry; editing a PDF in place invalidates the entry for that row.

Run logs

At capture="prompts" the prompt sidecar stores a placeholder instead of the file:

{"type": "document", "title": "acme.pdf", "media_type": "application/pdf",
 "bytes": 184320, "sha256": "9f2c..."}

Enough to tell two attachments apart, without putting a megabyte of base64 into every run log.

Request limits

Providers cap request size, and attachments are where you hit the caps. Base64 encoding inflates every file by 4/3, so 25 MB of PDFs is about 34 MB on the wire.

Limit Anthropic OpenAI Gemini
One request 32 MB 50 MB across its files 50 MB inline, for PDFs
One batch submission 256 MB (and 100,000 requests) 200 MB input file (and 50,000 requests) no batch path
PDF pages 600 per request, or 100 under a 1M-token context window none documented 1,000 per file

Sources: Anthropic request size limits, batch limitations, PDF support; OpenAI file inputs, Batch API; Gemini file input methods, document processing. accrue reads MB as 1,000,000 bytes and counts base64, the conservative readings: 50 MB is about 37 MB of PDFs.

What accrue does about them:

  • It estimates each request's size before sending. Document bytes are counted at their base64 length without being encoded; the rest of the request (prompt, schema, tools) is measured by serializing it, plus 1 KB for the provider envelope.
  • An over-limit row fails alone. If a row's request exceeds the client's per-request limit, the row gets a StepError naming the estimated size and the limit, no API call is made, and the rest of the run continues. This applies to realtime and batch steps. Pipeline.retry_failed() will retry the row, so shrink or split its attachments first.
  • Batches are split by size as well as count. A new batch starts before the summed estimate would pass EnrichmentConfig.batch_max_bytes, which defaults to the client's per-batch cap. A request that is bigger than the batch limit on its own fails that row instead of the batch.

The limits are the client attributes max_request_bytes and max_batch_bytes, in bytes. Set them on an instance for a gateway with tighter caps (Bedrock allows 20 MB per request, Google Cloud 30 MB), or to None to switch a check off:

client = AnthropicClient()
client.max_request_bytes = 20_000_000

config = EnrichmentConfig(batch_max_bytes=100_000_000)  # smaller batches

A custom client without these attributes is not checked.

Pages and tokens are not checked. Counting PDF pages reliably means parsing the PDF (page trees, compressed object streams, incremental updates), and accrue does not take a PDF dependency for that; a regex over the raw bytes miscounts real files. Token counts depend on the model's tokenizer and on how the provider renders each page. A file over the page limit, or a prompt over the context window, is still refused by the provider: on a realtime step the row fails with the provider's error, and on a batch step that one request fails inside the batch and is retried realtime, where it fails the same way. If your files are near the page limit, count pages yourself (for example with pypdf in a FunctionStep) and skip or split those rows before the LLMStep.

A realtime response cut off at max_tokens fails the row with an error naming the limit rather than being retried: every retry would resend the full request, documents included, and be cut off again. In an OpenAI batch, such a row is sent once more in realtime and fails there, so it is paid for twice. Raise max_tokens (on Anthropic above roughly 21,000, also pass AnthropicClient(timeout=...), see providers).

Attachment bytes are input tokens: a long PDF is a real cost, and the cached system prefix does not cover them.

Out of scope

  • Text extraction, OCR, or chunking — send the file, or pre-process it yourself in a FunctionStep.
  • Images, audio, and video blocks.
  • Remote URLs, the providers' Files APIs, and provider-side document caching.
  • Per-attachment token accounting beyond what the provider reports.