Skip to main content
File readers extract content from files attached to agent messages before they are sent to the model. This lets agents process PDFs, Word documents, presentations, spreadsheets, images, and audio files without manual preprocessing.
File readers (definable.reader) extract content from files attached to agent messages for LLM processing. They are distinct from Knowledge readers (definable.knowledge.reader), which convert raw sources into Document objects for the RAG pipeline.

Quick Example

Architecture

The readers module uses a layered design:
  • Parsers — stateless format converters: bytes → List[ContentBlock]. Never do I/O.
  • ParserRegistry — priority-based mapping from format to parser.
  • BaseReader — orchestrator: File → bytes → detect format → parse → ReaderOutput.
  • Providers — AI-backed readers (e.g., MistralReader) that handle their own API I/O.

Built-in Parsers

Install all parser dependencies at once:
Parsers with missing optional dependencies are silently skipped. Install only what you need.

ContentBlock

Content extraction produces ContentBlock objects — the multimodal output unit: Methods:

ReaderOutput

Every file read returns a ReaderOutput: Methods:

BaseReader

The main orchestrator that resolves files to parsed content:

Constructor

ReaderConfig
Reader configuration (file size limits, encoding, timeout).
ParserRegistry
Custom parser registry. When None, a default registry with all available parsers is created.

Methods

Agent Integration

Three ways to enable file readers on an agent:
When the agent receives files via run(..., files=[...]), it automatically extracts content from each file and injects it into the prompt before calling the model.

ReaderConfig

Configure reader behavior:

Creating a Custom Parser

Subclass BaseParser and implement three methods:
Register it with a reader:

MistralReader

AI-backed OCR provider using the Mistral OCR API. Handles PDFs, DOCX, PPTX, and images with high-quality extraction.
str
Mistral API key. Falls back to MISTRAL_API_KEY env var.
str
default:"mistral-ocr-latest"
OCR model to use.
bool
default:"false"
Include base64-encoded images in output blocks.
bool
default:"true"
Fall back to local parsers for formats Mistral doesn’t support.
Native formats: .pdf, .docx, .pptx, .png, .jpg, .jpeg, .avif
Requires mistralai: pip install 'definable[mistral-ocr]'

Parser Options

PDFParser

DocxParser

XlsxParser

OdsParser

ParserRegistry

The registry maps formats to parsers with priority-based dispatch:
Built-in parsers are registered at priority 0. User-registered parsers default to priority 100. Higher priority wins when multiple parsers handle the same format.

ReadersConfig

Configure the readers integration on the agent via AgentConfig:

Standalone Usage

Use BaseReader without an agent for file processing pipelines:

Audio Format Normalization

The reader.audio module provides utilities for normalizing audio formats. This is used internally by the audio_to_message() function in utils/openai.py and can be used standalone:

Supported Aliases

If the resolved format is not in the target set (wav, mp3 by default), ffmpeg is used to transcode. When ffmpeg is not installed, a RuntimeError is raised with install instructions.
For agent-level voice transcription (the common use case), use audio_transcriber=True on the Agent instead of calling normalize_audio_format directly. See Voice Note Transcription.

Stream Events

When using streaming, file reads emit events: