Amazon Textract Preprocessing Fixes RAG Failures on Complex Documents
In this article
Raw retrieval-augmented generation pipelines break on real enterprise documents. AWS Professional Services published a reference architecture on September 4, 2026, showing how Amazon Textract can serve as a preprocessing layer before documents enter an Amazon Bedrock Knowledge Base — directly addressing the hallucination and incomplete-extraction failures that occur when LLMs ingest unstructured PDFs, spreadsheets, and images without prior OCR normalization.
Why Naive RAG Fails on Complex Documents
The motivating scenario involves customer service teams processing high volumes of utility bills across six file formats: PDF, DOCX, TXT, HTML, XLSX, and PNG. Feeding raw files directly into a RAG model produced three failure categories. First, incomplete extraction: the LLM missed critical fields such as due dates, payment amounts, and account numbers. Second, hallucination: the model generated plausible but incorrect responses when it could not parse table structure or dense layout. Third, format inconsistency: performance degraded unevenly across document types because each format presents structurally different content to a tokenizer expecting linear text.
These are not prompt-engineering problems — they reflect a fundamental mismatch between the input representation and what the retrieval layer needs to embed meaningfully. As the case for pipeline architecture over model substitution continues to gain traction, this implementation is a concrete example of why preprocessing stages matter.
The Extraction and Enrichment Pipeline
The solution interposes Amazon Textract between raw document storage and the knowledge base. An S3 bucket named with the pattern document-<stack-name>-<partial-stack-id> receives uploads into a raw_files folder. That upload event triggers a document-parser Lambda function, which dispatches Amazon Textract jobs against the raw files. Textract handles multi-page PDFs with complex layouts and embedded images, tables in Word documents, cell contents from Excel spreadsheets, and text embedded in PNG files.
Processed output lands in a parsed_files folder; a second Lambda function converts that output to TXT format and writes the final artifacts to a parsed_kb_documents folder. The key value Textract adds is threefold: layout-aware extraction rather than linear tokenization, contextual labeling so table cells carry structural metadata rather than being flattened into undifferentiated text, and noise removal before embedding. Only the cleaned, labeled output reaches the Bedrock Knowledge Base sync operation, which uses an Amazon OpenSearch Serverless cluster as its vector store.
Infrastructure Composition and Deployment
The entire stack deploys through a single shell script (bash custom_kb_deployment_setup.sh) that invokes AWS CloudFormation. The stack provisions these resources:
| Resource | Type | Role in Pipeline |
|---|---|---|
| Lambda Execution Role | IAM Role | Permissions boundary for both Lambda functions |
| Lambda Layer | Lambda Layer | Shared dependency package for both functions |
| document-parser function | AWS Lambda | Triggers Textract jobs on S3 upload events |
| Second Lambda function | AWS Lambda | Converts Textract output to TXT for KB ingestion |
| S3 Bucket | Amazon S3 | Stores raw_files, parsed_files, parsed_kb_documents |
| OpenSearch Serverless Cluster | Amazon OpenSearch Serverless | Vector store backing the Bedrock Knowledge Base |
| Bedrock Knowledge Base | Amazon Bedrock | Managed RAG retrieval and generation endpoint |
| Bedrock KB IAM Role | IAM Role | Grants Knowledge Base access to S3 and OpenSearch |
Once the stack is live, a manual sync of the data source inside the Bedrock console completes ingestion. Testing uses the Amazon Nova Micro model, selected within the Knowledge Base console's configuration panel. Model availability is region-dependent and should be verified against the Supported Models by AWS Region table in the Bedrock documentation.
Guardrails and Production Hardening
The extraction pipeline alone cannot eliminate all risk. Amazon Bedrock Guardrails provides configurable controls for filtering harmful content, blocking denied topics, and redacting sensitive information from both model inputs and outputs. A grounding validation feature evaluates whether generated responses are actually supported by the retrieved source chunks — a direct mitigation for residual hallucination that can occur even after Textract preprocessing normalizes the input. The authors recommend enabling these controls explicitly for production deployments rather than relying on base model behavior. This reflects the infrastructure governance framing for safe agent deployment: safety properties are engineered into the surrounding stack, not assumed from the model itself.
The pattern generalizes beyond utility bills. Any domain where documents carry dense tabular data — insurance claims, financial statements, regulatory filings — faces the same extraction-before-embedding requirement. Event-driven OCR normalization feeding a managed vector store is CloudFormation-repeatable, meaning organizations can adapt it across document types without redesigning the retrieval layer each time. Preprocessing quality, not retrieval model quality, determines downstream answer accuracy.
Related Reading
FBG Multi-Agent Support System Cuts Containment Gap 56%
Fanatics Betting and Gaming's AWS multi-agent system improved containment 56% and resolution 53% in two months, using Claude, Nova Lite, and custom RAG.

Building a Production RAG Pipeline with Bedrock and OpenSearch Serverless
Everyone has shipped a RAG demo. Shipping one that survives real traffic, security audits, and finance reviews requires a different architecture. Explore the enterprise-grade RAG stack on AWS.
AWS Agent Registry Is Now Generally Available on Bedrock AgentCore
AWS Agent Registry hits GA, giving engineering teams a governed catalog for AI agents, tools, and skills with semantic search and EventBridge-wired approval workflows.