PDF Tool: Analyze Documents with Native Provider Support
Learn how the PDF tool extracts text from one or more PDF files, using native input for Anthropic and Google models and fallback extraction for other providers. This guide covers availability, model resolution, and input parameters.
Read this when
- You want to analyze PDFs from agents
- You need exact pdf tool parameters and limits
- You are debugging native PDF mode vs extraction fallback
pdf takes one or more PDF files and returns their textual content. For Anthropic and Google models it uses native document input, while for all other providers it falls back to text and image extraction.
Availability
This tool is registered only when OpenClaw can identify a PDF-capable model for the agent. The resolution follows this order:
agents.defaults.pdfModel(explicit primary and fallback models)agents.defaults.imageModel(explicit primary and fallback models)- The agent's resolved session or default model, provided its provider supports native PDF input (Anthropic, Google) or already has a configured vision model
- Auto-detected image and vision-capable providers with usable authentication, prioritizing native-PDF providers
Every fallback candidate undergoes authentication checks before use, so a configured provider/model counts only if OpenClaw can authenticate that provider for the agent. If no usable model resolves, the pdf tool remains unavailable.
Input reference
-
pdf(string), A single PDF file path or URL. -
pdfs(string[]), Multiple PDF paths or URLs, with a maximum of 10. -
prompt(string, default: Analyze this PDF document.), The prompt used for analysis. -
pages(string), A page filter such as1-5or1,3,7-9. Not available in native provider mode. -
password(string), Password for encrypted PDFs. Applies to all PDFs in the request and works only in extraction fallback mode. -
model(string), Optional model override formatted asprovider/model. -
maxBytesMb(number), Size cap per PDF in MB. Defaults toagents.defaults.pdfMaxMb, or10when not specified.
Notes:
pdfandpdfsare merged and deduplicated before loading; at least one must be provided.pagesis interpreted as 1-based page numbers, deduplicated, sorted, and clamped toagents.defaults.pdfMaxPages(default20). A range that matches no valid pages produces an error before the model call.
Supported PDF references
- Local file path (including
~expansion) file://URLhttp://andhttps://URL- OpenClaw-managed inbound references like
media://inbound/<id>
Other URI schemes (for example ftp://) return details.error = "unsupported_pdf_reference". Remote http(s) URLs are rejected when the tool runs in sandboxed mode. With workspace-only file policy enabled, local paths outside allowed roots are rejected, though managed inbound references and replayed paths under OpenClaw's inbound media store remain permitted.
Execution modes
Native provider mode
Used for provider anthropic and google, the only providers that currently support native PDF document input. Raw PDF bytes are sent directly to the provider API as a native document or inline-PDF part per file.
Limits:
pagesis unsupported; setting it causes the tool to throwpages is not supported with native PDF providers.passwordis unsupported; setting it causes the tool to throwpassword is not supported with native PDF providers. For encrypted PDFs, use a non-native model instead.
Extraction fallback mode
Used for all other providers.
- Text is extracted from the selected pages (up to
agents.defaults.pdfMaxPages, default20) using the bundleddocument-extractplugin, which relies on theclawpdfpackage (PDFium WebAssembly) for both text and image extraction. - If the extracted text is shorter than
200characters, the same pages are rendered as PNG images. The render budget is4,000,000pixels total, shared across all pages needing images (allocated proportionally per remaining page, not per page), so pages with sufficient text skip rendering entirely. - The extracted text (and any rendered images) along with the prompt are sent to the selected model.
Details:
- Encrypted PDFs are opened using the top-level
passwordparameter. - If the model lacks image input and no text can be extracted, the tool produces an error.
- If image rendering fails, OpenClaw discards the images and proceeds with the extracted text.
- If the target model is text-only and extraction generated images, OpenClaw discards the images and sends only text.
Config
{
agents: {
defaults: {
pdfModel: {
primary: "anthropic/claude-opus-4-6",
fallbacks: ["openai/gpt-5.4-mini"],
},
pdfMaxBytesMb: 10,
pdfMaxPages: 20,
},
},
}
| Key | Default | Meaning |
|---|---|---|
agents.defaults.pdfModel | unset | Explicit primary and fallback PDF models; falls back to imageModel, then the session model. |
agents.defaults.pdfMaxMb | 10 | Size cap per PDF in MB. |
agents.defaults.pdfMaxPages | 20 | Maximum pages processed per PDF. |
See Configuration Reference for complete field details.
Output details
The tool produces text content as content[0].text and organized metadata as details.
Frequently used details fields:
model: the final model reference (provider/model)native:truewhen using the native provider,falsewhen fallback is activeattempts: number of fallback attempts that failed before a successful one
Path-related fields:
- For a single PDF input:
details.pdf - For multiple PDF inputs:
details.pdfs[]containingpdfentries - Sandbox path rewrite metadata (if present):
rewrittenFrom
Error behavior
| Condition | Result |
|---|---|
| No PDF is provided | Raises pdf required: provide a path or URL to a PDF document |
| More than 10 PDFs | details.error = "too_many_pdfs" |
| Unsupported reference scheme | details.error = "unsupported_pdf_reference" |
pages with a native provider | Raises pages is not supported with native PDF providers |
password with a native provider | Raises password is not supported with native PDF providers |
Examples
Working with one PDF:
{
"pdf": "/tmp/report.pdf",
"prompt": "Summarize this report in 5 bullets"
}
Working with multiple PDFs:
{
"pdfs": ["/tmp/q1.pdf", "/tmp/q2.pdf"],
"prompt": "Compare risks and timeline changes across both documents"
}
Fallback model filtered by page:
{
"pdf": "https://example.com/report.pdf",
"pages": "1-3,7",
"model": "openai/gpt-5.4-mini",
"prompt": "Extract only customer-impacting incidents"
}
Encrypted PDF using extraction fallback:
{
"pdf": "/tmp/locked.pdf",
"password": "example-password",
"model": "openai/gpt-5.4-mini",
"prompt": "Summarize this contract"
}
Related
- Tools Overview - describes every agent tool
- Configuration Reference - explains pdfMaxBytesMb and pdfMaxPages settings