PaperTrail AI: Decentralized Intelligence for Complex Immigration Pathways
Inspiration
For millions of immigrants in the United States, receiving a piece of mail from USCIS—whether a Notice of Action (I-797) or a Request for Evidence (RFE)—triggers immediate anxiety. These critical notices arrive in dense, bureaucratic legalese with strict filing deadlines. Misinterpreting administrative language or missing a window by a single day can lead to loss of legal status, work authorization delays, or even deportation proceedings.
Existing options are polarized: expensive legal counsel is out of reach for many applicants, while basic commercial LLM wrappers lack legal grounding, hallucinate policy advice, and expose sensitive Personally Identifiable Information (PII) like Social Security Numbers and Alien Registration Numbers to cloud APIs. We were inspired to build PaperTrail AI to bridge this gap—creating an accessible, privacy-first, agentic copilot that translates complex legal notices into actionable checklists and spoken native-language guidance.
How We Built It
PaperTrail AI was engineered ground-up during the hackathon using a modular 5-tier architecture:
- Vision OCR & Privacy Ingestion Engine (
pii_redactor.py)
We implemented an OCR pipeline using OpenCV (deskewing, noise reduction, and Otsu thresholding) combined with Tesseract andpdfplumber. Before any data touches downstream LLMs, Microsoft Presidio and custom regular expressions strip out PII (A-Numbers, SSNs, dates of birth). - Grounded Policy RAG Pipeline (
policy_rag.py)
To prevent hallucinations, extracted administrative intent is contextualized against a local vector database built on official USCIS Policy Manuals and Title 8 of the Code of Federal Regulations (8 CFR). Using ChromaDB and local HuggingFace embeddings (sentence-transformers), search results are dynamically filtered by form code and case type. - Adversarial Multi-Agent Review Loop (
multi_agent_loop.py)
Orchestrated via LangGraph, two specialized agent personas simulate a legal review debate:- The Adjudicator: Simulates a strict USCIS reviewing officer who flags evidence gaps, missed deadlines, and denial risks.
- The Advocate: Translates the Adjudicator's critique and retrieved policy vectors into a prioritized checklist and draft response cover letter.
- Multilingual Speech Synthesis (
app.py)
Using gTTS, the final action plan is converted into real-time audio walkthroughs in native dialects (English, Spanish, Hindi, Tagalog, Simplified Chinese) for non-English speakers. - Backend & Frontend Services (
main.py&app.py)
An asynchronous FastAPI REST backend manages background task queues with Pydantic v2 validation, while a Streamlit web interface guides the user through document upload, risk analysis, and audio playback.
Key Mathematical Formulations & Algorithms
Risk Level Classification
To evaluate case risk, the system dynamically calculates the remaining deadline window \(\Delta t\) from the extracted response deadline \(t_{\text{deadline}}\) and current timestamp \(t_{\text{current}}\):
$$ \Delta t = t_{\text{deadline}} - t_{\text{current}} $$
The numerical Risk Score \(S\) combines deadline urgency with the severity density \(D\) of issues flagged by the Adjudicator:
$$ S = w_1 \cdot \left( \frac{1}{\max(1, \Delta t)} \right) + w_2 \cdot D $$
Where \(w_1\) and \(w_2\) are calibrated weights (\(w_1 = 0.6, w_2 = 0.4\)). If \(S \ge 0.75\), the document is categorized as HIGH RISK, triggering a second adversarial pass in our LangGraph state graph.
Chunk Relevance Metric
During retrieval, document chunks \(c_i\) are scored against the extracted document intent query \(q\) using cosine similarity over normalized embedding vectors:
$$ \text{Sim}(q, c_i) = \frac{\mathbf{v}q \cdot \mathbf{v}{c_i}}{|\mathbf{v}q| |\mathbf{v}{c_i}|} $$
A confidence threshold (\(\text{Sim} \ge 0.70\)) ensures that only highly relevant regulatory precedents are cited in the final report.
Challenges We Faced
- Managing Adversarial Loops Without Infinite Recursion: Designing a state machine where an Adjudicator and Advocate agent critique each other can easily lead to non-terminating execution loops. We solved this by implementing a bounded state condition in LangGraph with a maximum cap of two iterations (\(\text{iteration} < 2\)) and strict schema validation.
- Redacting PII Without Destroying Legal Meaning: Simple redaction can inadvertently obscure legal terms like "Form I-797C" or specific CFR section numbers. We built custom regex recognizers for Microsoft Presidio with granular confidence thresholds (0.9 for A-Numbers, 0.4 for SSN patterns) to strip sensitive personal numbers while preserving statutory context.
- Degraded Physical Notice Processing: Scanned community documents often exhibit skew, low contrast, and artifacts. Integrating an OpenCV image preprocessing pipeline prior to Tesseract OCR improved downstream entity extraction accuracy significantly over raw OCR.
What We Learned
- Agentic Design Patterns: Building an adversarial two-agent framework yielded far more thorough risk evaluations than single-prompt completions, effectively catching subtle legal triggers that standard LLMs miss.
- Privacy by Design: Implementing PII masking at the ingestion boundary proves that powerful AI utilities can be built without sacrificing user confidentiality.
- Multimodal Accessibility: Providing audio explanations in native dialects completely changes how non-technical users interact with complex legal advice, shifting the tool from an informational dashboard to an empowering assistant.
Log in or sign up for Devpost to join the conversation.