Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteThis project is a learning prototype for document-grounded legal Q&A: it retrieves passages from a collection of UAE law PDFs, drafts an answer with a language model, and checks the draft against the retrieved text. LangGraph coordinates the workflow, FastAPI exposes it as an API, and Streamlit provides a chat interface. It can help users inspect supporting passages; it is not a validated legal-answer engine or a production legal service.
What is Retrieval-Augmented Generation (RAG)?
Retrieval-augmented generation (RAG) gives a language model relevant material from an external collection before it writes a response. As Malaika Junaid describes it in her tutorial, “RAG allows an LLM to retrieve information from external documents before generating a response.” In this example, those documents are PDFs containing UAE legal materials.
As an Amazon Associate I earn from qualifying purchases.
The intended flow is:
- Extract text from PDF files.
- Split the text into smaller passages, or chunks, and create an embedding for each passage.
- Store the embeddings and associated text in a vector database.
- For a question, retrieve relevant passages and give them to the language model as context.
- Draft an answer from that context and check the draft against it.
RAG can make it easier to trace a response to documents, but retrieval is not proof that the documents are authoritative, up to date, complete, or applicable to a person’s situation. A model can also misread a passage or make a claim the passage does not support.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →What Are We Building?
The tutorial connects four layers. LangGraph manages the sequence of work; a vector store holds searchable document passages; FastAPI accepts a question and returns the result; and Streamlit lets a user enter a question and inspect the returned answer and source text.
#1 Best Overall
| Layer | Role in the example | What a user can inspect |
|---|---|---|
| PDF ingestion | Extracts, divides, embeds, and indexes document text. | The extracted text and the boundaries of individual chunks. |
| Vector store | Retrieves passages that are relevant to a question. | The passages returned as context. |
| LangGraph workflow | Routes retrieval, answer drafting, and draft checking. | The workflow’s pass, retry, or stop outcome. |
| FastAPI | Provides a /chat endpoint between the UI and workflow. |
The request and response fields. |
| Streamlit | Collects a question and displays the result and returned chunks. | The answer and expandable source text. |
The example question is “What is the probation period limit under UAE Labor Law?” It is a demonstration prompt only; the tutorial does not establish an answer to that legal question.
What you need before starting
The tutorial assumes basic Python, virtual-environment, and HTTP-request knowledge. It does not require prior LangGraph or Docker experience. You will also need the PDF documents you intend to index, the service credentials required by your chosen model and vector database, and a way to run the API and UI locally.
Keep credentials in environment variables or a local .env file, as the tutorial does, and exclude secret files from source control. Do not put provider keys directly in application code or a public repository. For any real legal or client information, consider the confidentiality and access requirements before sending data to an external service.
Understand the tutorial’s package versions
The versions below are the author’s dated dependency snapshot, not a current recommendation or a verified compatible package set. Check the current official documentation and release notes before selecting versions; the availability of newer versions does not establish that these particular pins work together today.
Rank #2
| Package | Tutorial pin | How to interpret it |
|---|---|---|
| FastAPI | 0.110.0 | Version pinned in the tutorial example. |
| LangGraph | 0.0.30 | Version pinned in the tutorial example. |
| LangChain | 0.1.13 | Version pinned in the tutorial example. |
| Pinecone client | 3.2.2 | Version pinned in the tutorial example. |
| Streamlit | 1.32.2 | Version pinned in the tutorial example. |
These values are reproducibility clues for the tutorial’s code, not a performance result or a supported installation matrix. A Python virtual environment helps keep this project’s dependencies separate from other Python applications. The tutorial’s directory organization separates data, backend schemas and application code, the frontend, ingestion, dependencies, environment secrets, and Docker configuration; treat it as a project layout to adapt, not a required framework convention.
Ingest the legal PDFs
The tutorial’s ingestion path is PDF → chunking → embeddings → Pinecone. Its specific demonstration settings are PyPDFLoader for PDF extraction, RecursiveCharacterTextSplitter with 1,000-character chunks and 150-character overlap, the all-MiniLM-L6-v2 embedding model, and a Pinecone index configured for 384 dimensions and cosine similarity. Those are example parameters, not universal settings for legal texts.
Validate extraction and chunk boundaries
Before relying on search results, compare the extracted text with the source PDF. Check that article numbers, headings, provisos, tables, amendment notes, and cross-references have not been dropped, scrambled, or separated from the text they qualify. Poor extraction can make a correct retrieval system return misleading or incomplete material.
Recommended Free Tools
Retain useful provenance with each passage, such as the official document name, jurisdiction, effective date or version, provision identifier, page number, and source URL when available. Overlap may help preserve nearby context across a split, but it cannot repair missing text or guarantee that a chunk contains all the conditions needed to interpret a provision.
Define the API boundary
The example uses Pydantic models to make the request and response shape explicit. A query must contain 5–500 characters; the response includes a verified_answer and a list of source strings. That is a minimal interface, not a complete citation system.
For a more inspectable response, return structured source records rather than bare text strings. Include fields such as document title, jurisdiction, effective date or version, provision identifier, page, and URL where the source provides them. This helps a person locate the passage and assess whether it is relevant; it still does not certify the model’s interpretation.
Orchestrate retrieval, drafting, and checking with LangGraph
The tutorial’s graph is a control-flow pattern rather than a collection of independent legal experts. It retrieves context, asks a synthesizer to draft using that context, and sends the draft to a checking node. Conditional routing approves the draft, stops when the retry limit is reached, or returns a rejected draft for another synthesis attempt.
- Retrieve: search the indexed passages for material relevant to the user’s question.
- Draft: ask the language model to answer from the supplied context.
- Check: compare the draft with the retrieved text.
- Route: accept the draft, retry synthesis, or stop when the configured retry limit is reached.
The check is another generated-model step. It may fail to notice an unsupported assertion, and it cannot establish whether the indexed law is binding, current, complete, or applicable to the user’s facts. A UI status such as “Verification Passed” means only that the program’s gate approved the draft under its configured logic. It is not independent legal validation.
Make uncertainty visible
A safer interface should abstain or clearly report uncertainty when no useful source is retrieved, when the retrieved passages conflict, or when a question requires facts the user has not provided. Show the relevant passages and their provenance alongside the answer. Do not convert a successful workflow status into a claim that an answer is correct.
LangChain’s learning materials describe custom RAG agents built with LangGraph primitives and patterns involving subagents, handoffs, and knowledge-base routing. Its LangGraph framework page describes human-in-the-loop controls and customizable single-agent, multi-agent, and hierarchical workflows. These materials support the general orchestration approach; they do not validate this tutorial’s exact package pins or establish legal-answer accuracy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Expose the workflow through FastAPI and Streamlit
FastAPI backend
The tutorial’s FastAPI service accepts a typed chat request at /chat, invokes the graph, and returns an answer with context chunks. Its example maps errors to HTTP 500. That demonstrates a basic service boundary, but broad server errors are not a production error-handling or security design.
Streamlit frontend
The Streamlit application sends a request to localhost:8000/chat, renders the answer, and puts returned chunks in an expandable section. The author’s stated purpose is “To provide an interactive web UI with expandable source citations so users can verify the AI’s claims.” Displaying source text supports inspection; it does not itself verify legal correctness.
Best Value
Docker scope
The tutorial’s Docker example packages a Python 3.10 backend application and exposes port 8000. The shown Dockerfile is for the backend; it does not separately package or launch the Streamlit frontend. Running that container alone therefore does not provide the complete two-part local interface.
What this prototype does not establish
- Legal accuracy: no evaluation results establish that this build answers legal questions accurately or prevents hallucinations.
- Corpus quality: a checking loop cannot compensate for missing, outdated, incorrectly extracted, or non-authoritative documents.
- Applicability: retrieved text alone cannot determine how a rule applies to a person’s facts or whether another legal source changes the analysis.
- Production security: a local endpoint and demonstration error handling do not implement authentication or authorization, request limits, safe logging, production secret management, or deployment network controls.
- UAE compliance: the example corpus concerns UAE law, but this guide does not establish current UAE deployment, data-protection, or professional-practice requirements.
Choose a workflow that fits the use case
The tutorial demonstrates one vector-store workflow with a draft-and-check loop; it does not benchmark the alternatives below. These are design choices to evaluate against the documents, risks, and user needs of a project.
| Design choice | What it changes | Consider when |
|---|---|---|
| Deterministic retrieval pipeline vs. agentic or tool-calling control | A fixed sequence has more predictable steps; an agentic workflow can choose among tools or routes but adds control complexity. | The process is stable and narrow, or it genuinely needs multiple tools and conditional routes. |
| One model pass vs. draft-and-check loop | A second model step adds a review gate and possible retries, but is not independent proof of correctness. | A review signal is useful, provided its limits and failure cases are visible. |
| Vector-only vs. hybrid or metadata-aware retrieval | Vector search ranks by semantic similarity; lexical and metadata filters can help target exact terms, provisions, dates, or jurisdictions. | Exact statutory wording, document version, or jurisdiction is central to finding the right passage. |
| Public demonstration data vs. confidential material | Confidentiality, permissions, and provider handling become essential when documents or questions contain sensitive information. | Before indexing or sending non-public legal or client information to any service. |
Legal-domain safeguards and jurisdiction
For legal use, treat generated answers as material for human review, not as legal advice. The State Bar of Arizona’s guidance says legal professionals should verify AI work and use adequate confidentiality safeguards, including encryption and access controls; it also recommends examining whether providers use submitted information for training or share it. This is Arizona-specific professional guidance, not a statement of UAE law.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Because this example is framed around UAE legal documents, a deployment involving UAE users or data needs separately verified, authoritative guidance for the relevant jurisdiction and use. Do not infer local compliance from the fact that the demo indexes UAE law.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




