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:
ContentBlock
Content extraction producesContentBlock objects — the multimodal output unit:
Methods:
ReaderOutput
Every file read returns aReaderOutput:
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: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
SubclassBaseParser and implement three methods:
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.
.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: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 viaAgentConfig:
Standalone Usage
UseBaseReader without an agent for file processing pipelines:
Audio Format Normalization
Thereader.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.