# ravirajdeshpande/rag-and-guardrails architecture

> Architecture diagram of the GitHub repository ravirajdeshpande/rag-and-guardrails, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ravirajdeshpande/rag-and-guardrails
- Repository: https://github.com/ravirajdeshpande/rag-and-guardrails

## Overview

This is a LangGraph question-answering study project combining PDF ingestion, retrieval-augmented answers, and input/output guardrails. The README describes fitness questions, while sampled prompts and guardrail labels refer to passport and visa information, so the domain appears inconsistent. The documented user flow is question → input checks → retrieval and answer generation → output check or refusal. Ingestion and search stages are documented; unsampled implementation details are represented only at their supported directory paths.

Main entry points: [`src/fitness_agent/agent/nodes.py`](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/agent/nodes.py) (Workflow nodes), [`src/fitness_agent/guardrails/nlu_guard.py`](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/guardrails/nlu_guard.py) (NLU input classifier), [`src/fitness_agent/guardrails/output_guard.py`](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/guardrails/output_guard.py) (Answer judge), [`src/fitness_agent/agent/graph.py`](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/agent/graph.py) (LangGraph workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Document ingestion"]
  node_loader["Page loader<br/>[loader.py]"]
  node_chunker["Chunk splitter<br/>[chunker.py]"]
  node_ingestion_store["Embed and store<br/>[ingestion.py]"]
  node_vector_store[("Chroma vector store<br/>[vector_store.py]")]
end

subgraph group_rag["Retrieval and answers"]
  node_rewriter["Query rewriter<br/>[query_rewriter.py]"]
  node_retriever["Top-K retrieval<br/>[retriever.py]"]
  node_context["Context builder<br/>[context_builder.py]"]
  node_generator["Answer generator<br/>[generator.py]"]
  node_llm["Chat models<br/>[llm.py]"]
end

subgraph group_safety["Guardrails"]
  node_regex["Regex input check<br/>[regex_guard.py]"]
  node_nlu["NLU input classifier<br/>[nlu_guard.py]"]
  node_training_data["Classifier examples"]
  node_output_guard["Answer judge<br/>[output_guard.py]"]
  node_result["Guardrail result<br/>[result.py]"]
end

subgraph group_agent["Agent orchestration"]
  node_graph["LangGraph workflow<br/>[graph.py]"]
  node_nodes["Workflow nodes<br/>[nodes.py]"]
  node_state["Agent state<br/>[state.py]"]
  node_config["Settings<br/>[config.py]"]
end

node_user(("Questioner"))
node_pdfs["PDF documents"]
node_answer(("Answer or refusal"))

node_pdfs -->|"loads pages"| node_loader
node_loader -->|"splits pages"| node_chunker
node_chunker -->|"stores chunks"| node_ingestion_store
node_ingestion_store -->|"writes vectors"| node_vector_store
node_user -->|"asks question"| node_graph
node_graph -->|"dispatches nodes"| node_nodes
node_nodes -->|"reads and updates"| node_state
node_nodes -->|"checks input"| node_regex
node_nodes -->|"classifies input"| node_nlu
node_nlu -->|"trains from"| node_training_data
node_nodes -->|"rewrites question"| node_rewriter
node_nodes -->|"retrieves chunks"| node_retriever
node_retriever -->|"queries"| node_vector_store
node_nodes -->|"builds context"| node_context
node_nodes -->|"generates answer"| node_generator
node_nodes -->|"checks answer"| node_output_guard
node_output_guard -->|"judges output"| node_llm
node_rewriter -->|"requests rewrite"| node_llm
node_generator -->|"requests answer"| node_llm
node_nodes -->|"reads top-K"| node_config
node_regex -->|"returns verdict"| node_result
node_nlu -->|"returns verdict"| node_result
node_output_guard -->|"returns verdict"| node_result
node_graph -->|"returns result"| node_answer

click node_pdfs "https://github.com/ravirajdeshpande/rag-and-guardrails/tree/main/data/pdfs"
click node_loader "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/loader.py"
click node_chunker "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/chunker.py"
click node_ingestion_store "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/ingestion.py"
click node_vector_store "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/vector_store.py"
click node_rewriter "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/query_rewriter.py"
click node_retriever "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/retriever.py"
click node_context "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/context_builder.py"
click node_generator "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/generator.py"
click node_llm "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/llm.py"
click node_regex "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/guardrails/regex_guard.py"
click node_nlu "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/guardrails/nlu_guard.py"
click node_training_data "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/data/guardrail_training.csv"
click node_output_guard "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/guardrails/output_guard.py"
click node_result "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/guardrails/result.py"
click node_graph "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/agent/graph.py"
click node_nodes "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/agent/nodes.py"
click node_state "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/agent/state.py"
click node_config "https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/config.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_loader,node_chunker,node_ingestion_store,node_vector_store toneBlue
class node_rewriter,node_retriever,node_context,node_generator,node_llm toneAmber
class node_regex,node_nlu,node_training_data,node_output_guard,node_result toneMint
class node_graph,node_nodes,node_state,node_config toneRose
class node_user,node_answer toneIndigo
class node_pdfs toneTeal
```

## Components

### Document ingestion

- [Page loader](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/loader.py): `src/fitness_agent/rag/loader.py`
- [Chunk splitter](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/chunker.py): `src/fitness_agent/rag/chunker.py`
- [Embed and store](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/ingestion.py): `src/fitness_agent/rag/ingestion.py`
- [Chroma vector store](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/vector_store.py): `src/fitness_agent/rag/vector_store.py`

### Retrieval and answers

- [Query rewriter](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/query_rewriter.py): `src/fitness_agent/rag/query_rewriter.py`
- [Top-K retrieval](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/retriever.py): `src/fitness_agent/rag/retriever.py`
- [Context builder](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/context_builder.py): `src/fitness_agent/rag/context_builder.py`
- [Answer generator](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/rag/generator.py): `src/fitness_agent/rag/generator.py`
- [Chat models](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/llm.py): `src/fitness_agent/llm.py`

### Guardrails

- [Regex input check](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/guardrails/regex_guard.py): `src/fitness_agent/guardrails/regex_guard.py`
- [NLU input classifier](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/guardrails/nlu_guard.py): `src/fitness_agent/guardrails/nlu_guard.py`
- [Classifier examples](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/data/guardrail_training.csv): `data/guardrail_training.csv`
- [Answer judge](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/guardrails/output_guard.py): `src/fitness_agent/guardrails/output_guard.py`
- [Guardrail result](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/guardrails/result.py): `src/fitness_agent/guardrails/result.py`

### Agent orchestration

- [LangGraph workflow](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/agent/graph.py): `src/fitness_agent/agent/graph.py`
- [Workflow nodes](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/agent/nodes.py): `src/fitness_agent/agent/nodes.py`
- [Agent state](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/agent/state.py): `src/fitness_agent/agent/state.py`
- [Settings](https://github.com/ravirajdeshpande/rag-and-guardrails/blob/main/src/fitness_agent/config.py): `src/fitness_agent/config.py`

### Other components

- **Questioner**
- [PDF documents](https://github.com/ravirajdeshpande/rag-and-guardrails/tree/main/data/pdfs): `data/pdfs`
- **Answer or refusal**

## Connections

- PDF documents → Page loader: loads pages (evidence: `README.md`)
- Page loader → Chunk splitter: splits pages (evidence: `README.md`)
- Chunk splitter → Embed and store: stores chunks (evidence: `README.md`)
- Embed and store → Chroma vector store: writes vectors (evidence: `src/fitness_agent/rag/ingestion.py`)
- Questioner → LangGraph workflow: asks question (evidence: `README.md`)
- LangGraph workflow → Workflow nodes: dispatches nodes (evidence: `src/fitness_agent/agent/graph.py`)
- Workflow nodes → Agent state: reads and updates (evidence: `src/fitness_agent/agent/nodes.py`)
- Workflow nodes → Regex input check: checks input (evidence: `src/fitness_agent/agent/nodes.py`)
- Workflow nodes → NLU input classifier: classifies input (evidence: `src/fitness_agent/agent/nodes.py`)
- NLU input classifier → Classifier examples: trains from (evidence: `README.md`)
- Workflow nodes → Query rewriter: rewrites question (evidence: `src/fitness_agent/agent/nodes.py`)
- Workflow nodes → Top-K retrieval: retrieves chunks (evidence: `src/fitness_agent/agent/nodes.py`)
- Top-K retrieval → Chroma vector store: queries (evidence: `src/fitness_agent/rag/retriever.py`)
- Workflow nodes → Context builder: builds context (evidence: `src/fitness_agent/agent/nodes.py`)
- Workflow nodes → Answer generator: generates answer (evidence: `src/fitness_agent/agent/nodes.py`)
- Workflow nodes → Answer judge: checks answer (evidence: `src/fitness_agent/agent/nodes.py`)
- Answer judge → Chat models: judges output (evidence: `src/fitness_agent/guardrails/output_guard.py`)
- Query rewriter → Chat models: requests rewrite (evidence: `src/fitness_agent/rag/query_rewriter.py`)
- Answer generator → Chat models: requests answer (evidence: `src/fitness_agent/rag/generator.py`)
- Workflow nodes → Settings: reads top-K (evidence: `src/fitness_agent/agent/nodes.py`)
- Regex input check → Guardrail result: returns verdict (evidence: `README.md`)
- NLU input classifier → Guardrail result: returns verdict (evidence: `src/fitness_agent/guardrails/nlu_guard.py`)
- Answer judge → Guardrail result: returns verdict (evidence: `src/fitness_agent/guardrails/output_guard.py`)
- LangGraph workflow → Answer or refusal: returns result (evidence: `README.md`)
