TL;DR
- I built americanvisa.ai, a RAG assistant that answers F-1 student, OPT and H-1B questions from 54 official sources and cites every sentence.
- The hard part: immigration rules get proposed, blocked by courts and appealed, and the official regulation website can show text a court has stopped. Plain RAG can't tell the difference.
- On 14 held-out questions it covered 89% of expected points, against 76% for plain RAG and 73% for the model alone. On questions about whether a rule applies, turning off the rule-status layer dropped correctness from 100% to 58%.
The site gives information, not legal advice.
What it does
You ask a question like "Can I travel while my STEM OPT extension is pending?" The answer comes with three things:
- A rule-status card: each rule the answer depends on, with its status on the question's date ("IN EFFECT", "VACATED by a court, appeal pending") and when that status was last checked.
- An answer where every factual sentence cites a numbered source or a status line.
- The sources it cited, linked to the official pages, with their authority level and the date of the text.
The pipeline
It's a standard RAG pipeline, with a few choices made for legal text. The orange parts are the rule-status layer, covered in its own section below.
Stack: Python 3.12, FastAPI with server-rendered Jinja2 pages, Postgres 16 with pgvector, local embeddings, Claude Haiku 5.5 for cheap steps and Claude Sonnet 5.5 for answers. It runs as one container on Railway, with the database on Neon.
1. Sources and versioned ingestion
54 official sources: regulation sections from the eCFR, Federal Register rules, USCIS pages and its Policy Manual, Study in the States, and court orders. Each has an authority tier that the model sees next to every chunk: binding (1), official guidance (2), or proposed, not law (3).
Ingestion keeps history. The eCFR's versioning API returns every past version of a regulation section, so the database has each version since January 2024. Every chunk gets valid_from and valid_to dates, and nothing is overwritten.
2. Chunking
Chunks follow the document's structure (regulation paragraphs, page headings) and stay under 500 tokens. Each one starts with a header saying where it comes from:
[8 CFR 214.2(f)(10)(ii)(E) · F-1 academic students > Practical training > Optional practical training > Periods of unemployment during post-completion OPT] (E) Periods of unemployment during post-completion OPT. During post-completion OPT, ... Regulation paragraphs rarely name their subject, so without the header, "(E) Periods of unemployment" has no "F-1" or "OPT" in its embedding. The header gives each chunk its context without overlap's duplicated text.
3. Embeddings
BAAI/bge-base-en-v1.5, run locally. The whole corpus (about 3,950 current chunks) embeds in about 1.5 minutes on a laptop, at no cost.
4. Routing
A cheap Haiku call reads the question first. It decides whether the question is in scope, which tracked rules it's about, and the date it's asking about ("back in March 2026", otherwise today). It also decides whether something has already happened in the user's own case, such as a denial; those get a fixed referral to an attorney. Before this step, receipt numbers, SEVIS IDs, emails and phone numbers are masked.
5. Hybrid retrieval
Three ranked lists, merged with weighted reciprocal rank fusion:
- Vector search with pgvector;
- Keyword search with Postgres full-text search;
- Exact citation matches, so "214.2(f)(11)" finds that paragraph. These are weighted 3×.
Only text valid on the question's date is considered:
(valid_from IS NULL OR valid_from <= :as_of) AND (valid_to IS NULL OR valid_to > :as_of) So "what was the H-1B registration fee in March 2024?" retrieves the $10 fee, and the same question today retrieves $215. At most 3 chunks per source are kept, so one long Federal Register preamble can't fill all 12 slots.
6. Generation with required citations
Sonnet gets the numbered sources, each with its tier and date, and must cite every factual sentence: [3] for a source. It's told to prefer binding sources over guidance and to say when they differ, and to say plainly when the sources don't answer the question.
7. Checks and fallback
After generation:
- every citation must point to a real source;
- every factual sentence must be cited;
- a Haiku check confirms the answer doesn't present a proposed or on-hold rule as law.
A failed draft gets one retry with the reasons. If the retry fails too, the user gets the sources and statuses without generated text. A visitor never sees an unchecked answer.
The part plain RAG doesn't do: rule status
In 2025 and 2026, many US student and work-visa rules were announced and then blocked, postponed or appealed. The clearest case is the rule replacing F-1 "duration of status" with fixed admission periods:
- July 2026: final rule published, effective September 15.
- September 14: a court postponed it.
- September 15: the eCFR switched to the new text anyway. Among other things, it cuts the deadline to apply for OPT from 60 days after graduation to 30.
- November 16: the court vacated the rule.
For two months, the official regulation website showed a rule that didn't apply. Date-filtered retrieval correctly returns that text, because it is officially current. Similarity search can't help either: a proposed or blocked rule reads exactly like one in effect.
Legal research tools have handled this for decades with citators: editors keep a status record for each case or statute, separate from its text. I built a small version of that pattern for an LLM.
A rule table, checked by hand. 15 rules that are new, changing or contested. Each has dated events with primary sources:
- id: dhs-duration-of-status-2026 events: - {date: 2025-08-28, status: proposed, source: fr-dos-nprm} - {date: 2026-07-17, status: final_pending, effective: 2026-09-15, source: fr-dos-final-rule} - {date: 2026-09-14, status: postponed, source: "court-presidents-alliance-dos#51"} - {date: 2026-11-16, status: vacated, appeal_pending: true, source: "court-presidents-alliance-dos#73"} last_verified: 2026-11-22 A rule's status on a date is its latest event on or before that date. A person edits this table, because a wrong status is the most harmful mistake the system can make, and court orders are easy to misread.
Status as an authoritative source. The statuses go into the prompt as a RULE STATUS block that outranks every document, and the answer cites it like a source: [R1]. The status check enforces it.
Swapping out text a court has stopped. Regulation paragraphs are tagged with the rules that changed them (the paragraphs whose text changed on a rule's effective date). When a retrieved paragraph belongs to a rule that's on hold, it's replaced by the version of the same paragraph that ended on that date, labeled as the text that still applies. A status line alone wasn't enough: the model sometimes trusted the binding-looking regulation over it, and told a user the 30-day deadline controlled.
Evaluation
72 questions, each with a date, expected points, required sources, statements it must not make, and whether it should refer the user to a school official (DSO) or an attorney. 14 were held out and run once at the end. A Claude judge scored the answers; on a blind sample of 68 of its decisions, it agreed with my scores 94% of the time.
Held-out set (14 questions):
| Metric | Model alone | Plain RAG | This system |
|---|---|---|---|
| Correctness (expected points covered) | 73% | 76% | 89% |
| States a rule's status wrongly | 14% | 0% | 0% |
| Referral given when expected | 86% | 86% | 100% |
| Out-of-scope questions declined | 0% | 0% | 100% |
| Cost per answer | $0.012 | $0.025 | $0.036 |
Plain RAG here is vector search over every version, with no date filter and no status layer.
Ablation: the full system against the same system with the rule-status layer turned off, keeping everything else, including date-filtered retrieval.
| Metric | Full system | No status layer |
|---|---|---|
| Correctness, all 72 questions | 92% | 80% |
| Correctness, the 16 rule-status and rumor questions | 100% | 58% |
| States a rule's status wrongly, those 16 | 0% | 19% |
Without the layer, asked whether the duration-of-status rule affects a STEM OPT student, the system described the rule and said it couldn't confirm when it applies. It never mentioned the court order. Documents don't announce that a court stopped them. The layer costs a few hundred tokens and one Haiku call.
