The RAG Pattern That Stops LLMs From Inventing Fields That Don't Exist | SuperML.dev β AI/ML Architecture for Enterprise
NEW SuperML.dev repo is now available! Β» AgenticAI
Login
π¬ Subscribe<br>Γ π©
SuperML.dev Newsletter
Get weekly ML & AI tutorials, tools, and project updates β straight to your inbox. No spam, unsubscribe anytime.
Subscribe Now β
AI & Machine Learning<br>The RAG Pattern That Stops LLMs From Inventing Fields That Don't Exist<br>Standard RAG retrieves documents and lets the LLM generate field names freely β which means it will invent fields your schema never had. AK-RAG (Attribute Knowledge RAG) indexes your governed attribute catalog instead, and the LLM can only emit attribute_ids that actually exist. Here's the architecture and why it matters for regulated-industry AI.<br>Jul 6, 2026<br>crazyaiml
Share this article<br>Comments Shorts
Share:
Table of Contents
Every team building RAG for a regulated enterprise hits the same failure mode eventually. The system retrieves the right context β clinical guidelines, product documentation, data dictionaries β and the LLM produces a confident, fluent response that references fields, thresholds, and identifiers that donβt exist in the actual data model. In a consumer app this is a nuisance. In a bankβs credit underwriting pipeline, a healthcare payerβs cohort identification system, or a compliance teamβs AML query layer, it is a governance failure. The LLM invented a field. That field never went through data governance. The output is meaningless at best and misleading at worst.
Standard RAG was not designed to prevent this. It retrieves document chunks and hands them to the LLM as context. The LLM then generates free-form text, including any field names, identifiers, and thresholds it infers from that context. There is no guarantee that what the LLM generates corresponds to anything that actually exists in your data catalog. Prompt-level mitigations β instructions to only use fields from the provided context, few-shot examples, output validation β help at the margins but donβt solve the structural problem. The problem is that the retrieval unit is wrong.
Attribute Knowledge RAG (AK-RAG) is a reference architecture that fixes this at the retrieval unit level. Instead of embedding documents, it indexes your governed attribute catalog as individual knowledge objects β one embedding per attribute, not one embedding per document page. The LLMβs job is phrase extraction and clarification dialog, not field name generation. The only identifiers that can appear in the final output are attribute_id values that exist in the indexed catalog. The LLM cannot invent fields because field selection happens through a governed retrieval and classification pipeline, not through free generation.
Architecture
AK-RAG has two distinct pipelines: an ingestion pipeline that builds the attribute index, and a query pipeline that translates natural language into a governed DSL. Both are designed around a core principle: the attribute catalog is the knowledge layer, not the document corpus .
Ingestion Pipeline
The ingestion pipeline takes your enterprise attribute metadata β typically maintained in Excel, CSV, or exposed via an API β and transforms it into a searchable, versioned index:
Excel / CSV / API<br>Contract Validation & Normalization<br>- Split synonyms<br>- Parse ranges and thresholds<br>- Coerce types, standardize units/dates<br>NDJSON (One Attribute = One Document)<br>ββββββββββββββββββββββββββββββββββββββββ<br>β Embedding Provider β<br>β sentence-transformers (dev) β<br>β openai Β· gemini Β· bedrock (prod) β<br>ββββββββββββββββββββββββββββββββββββββββ<br>ββββββββββββββββββββββββββββββββββββββββ<br>β Search / Index Backend β<br>β local BM25 + token vector + RRF β β offline, no cluster (dev)<br>β opensearch BM25 + HNSW kNN + RRF β β production<br>β faiss / chroma β β dense vector alternatives<br>ββββββββββββββββββββββββββββββββββββββββ<br>Each attribute becomes a single NDJSON document. Hereβs what that looks like for a clinical attribute in the healthcare domain:
"attribute_id": "clinical.hba1c",<br>"type": "numeric",<br>"business_name": "HbA1c Level",<br>"technical_field": "hba1c_pct",<br>"domain": "clinical",<br>"definition": "Most recent HbA1c percentage on record. Indicates glycemic control...",<br>"synonyms": ["glycated hemoglobin", "blood sugar control", "a1c", "hemoglobin a1c"],<br>"operators": [">", ">=", ", ", "="],<br>"unit": "%",<br>"example_values": [7.0, 8.0, 9.0, 10.0],<br>"governance": {<br>"phi": true,<br>"hipaa_category": "clinical",<br>"de_identification_required": false,<br>"minimum_cell_size": 11,<br>"allowed_channels": ["care_management", "quality_reporting", "analytics"],<br>"consent_required": false<br>},<br>"embedding_text": "numeric | HbA1c Level | hba1c_pct | glycated hemoglobin | blood sugar control | a1c | glycemic control | diabetes | percentage | clinical"<br>The embedding_text field is hand-composed to maximize retrieval signal: it concatenates the type, business name, technical field name, synonyms, definition keywords, and domain tags. This...