Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CrewAIInc CrewAI ContextualAI Parse Tool

From Leeroopedia
Knowledge Sources
Domains Tools, Document_Parsing, ContextualAI
Last Updated 2026-02-11 00:00 GMT

Overview

Concrete tool for parsing documents using Contextual AI's advanced document parser provided by CrewAI.

Description

The ContextualAIParseTool class extends BaseTool to parse complex documents including tables, figures, and multi-column layouts via Contextual AI's REST API (https://api.contextual.ai/v1/parse). The _run method executes a three-phase process: first, it submits a parse job with the document file and configuration parameters; second, it polls the job status every 5 seconds until completion or failure; third, it retrieves the parsed results with specified output types. Configuration options include parse_mode (standard), figure_caption_mode (concise), enable_document_hierarchy, page_range, and output_types (defaulting to markdown-per-page). The tool uses direct REST requests rather than an SDK, with bearer token authentication.

Usage

Use this tool when CrewAI agents need to preprocess complex PDF documents before ingesting them into RAG systems, enabling semantic search over structured content extracted from challenging document formats.

Code Reference

Source Location

  • Repository: CrewAI
  • File: lib/crewai-tools/src/crewai_tools/tools/contextualai_parse_tool/contextual_parse_tool.py
  • Lines: 1-108

Signature

class ContextualAIParseTool(BaseTool):
    name: str = "Contextual AI Document Parser"
    description: str = "Parse documents using Contextual AI's advanced document parser"
    args_schema: type[BaseModel] = ContextualAIParseSchema
    api_key: str

    def _run(self, file_path: str, parse_mode: str = "standard",
             figure_caption_mode: str = "concise",
             enable_document_hierarchy: bool = True,
             page_range: str | None = None,
             output_types: list[str] | None = None) -> str: ...

Import

from crewai_tools import ContextualAIParseTool

I/O Contract

Inputs

Name Type Required Description
api_key str Yes Contextual AI API key (constructor)
file_path str Yes Path to the document to parse
parse_mode str No Parsing mode (default "standard")
figure_caption_mode str No Figure caption mode (default "concise")
enable_document_hierarchy bool No Enable document hierarchy extraction (default True)
page_range str or None No Page range to parse (e.g., "0-5")
output_types list[str] or None No List of output types (default ["markdown-per-page"])

Outputs

Name Type Description
_run() returns str JSON string containing parsed document content with the specified output types

Usage Examples

Basic Usage

from crewai_tools import ContextualAIParseTool

tool = ContextualAIParseTool(api_key="your-api-key")
result = tool.run(
    file_path="./documents/report.pdf",
    parse_mode="standard",
    page_range="0-10",
    output_types=["markdown-per-page"]
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment