-
Notifications
You must be signed in to change notification settings - Fork 1
Document Processing Pipeline
The Document Processing Pipeline transforms raw legal files into structured, machine-readable data. It handles the ingestion, parsing, semantic structuring, and analysis of various document formats (PDF, DOCX, HTML).
The pipeline follows a structured sequence of operations:
flowchart TD
Start[Raw File/Input] --> Classify[Classify Intent]
Classify --> Parse[Parse Document]
Parse --> Sectionize[Extract Sections]
Sectionize --> Analyze[Analyze Patterns]
Analyze --> Synthesize[Synthesize Answer]
Synthesize --> Validate[Validate Response]
Validate --> End[Structured Output/Report]
The parsing stage extracts raw text and metadata from various file formats. It supports PDF, DOCX, and HTML inputs with native text extraction and OCR fallback for scanned documents.
- DocumentParser: Coordinates file conversion. Supports Ukrainian, Russian, and English languages.
- parse_document Tool: An MCP tool that accepts a Base64-encoded file and returns extracted text, page count, and source metadata.
The extract_document_sections tool (via SemanticSectionizer) transforms raw text into logical sections. This is critical for legal documents where meaning is derived from specific parts such as "Facts," "Reasoning," and "Decision."
graph TD
RawText[Raw Text Stream] --> Sizer[Semantic Sectionizer]
Sizer --> Facts[Facts Section]
Sizer --> Reasoning[Reasoning Section]
Sizer --> Decision[Decision Section]
Sizer --> Norms[Legal Norms Section]
After structuring, the pipeline provides tools for deep legal analysis using budget-aware LLM execution:
- extract_key_clauses: Identifies legal clauses (payments, liability, termination) and assigns risk levels.
- summarize_document: Generates executive and detailed summaries segmented by sections.
- compare_documents: Performs semantic comparison between document versions, classifying changes by importance.
The pipeline includes a final validation step to prevent hallucinations:
- validate_response: Checks the synthesized answer against original document sections. Every key claim must have a corresponding citation in the source document.
-
Citation Requirements: Citations must include
source_id,quote, andurlto be valid.