cd /news/ai-agents/building-an-agent-that-can-t-afford-… Β· home β€Ί topics β€Ί ai-agents β€Ί article
[ARTICLE Β· art-144729] src=dev.to β†— pub= topic=ai-agents verified=true sentiment=↑ positive

Building an Agent That Can't Afford to Be Wrong: Quran Sanity Agent

A developer built Quran Sanity Agent, an open-source bilingual (Arabic and English) research workspace that anchors every verse, translation, and scholarly commentary to immutable records in Sanity's Content Lake so the agent cannot generate Quranic text itself. The TypeScript monorepo combines deterministic GROQ lookups (sub-50ms) with a Sanity Context MCP endpoint over 21,398 library chunks, and the Next.js workspace verifies candidate document IDs and rejects AI notes lacking verbatim source quotes. The project is live and its code is available on GitHub.

by read4 min views1 publishedOct 4, 2026

This is a submission for the Sanity Challenge, Path One: Ship an Agent That Queries Real Content

When I first opened the Sanity Challenge announcement, one sentence in the Path One brief immediately grabbed my attention:

"Build anything that needs an answer it can't afford to get wrong."

That one line defined this entire project.

If you ask an AI chatbot for movie recommendations or a recipe, a small hallucination is harmless. But if you ask it about the Quran, religious scripture, or classical commentary, getting things wrong is not an option.

Yet that is exactly what standard LLMs do every day:

Traditional RAG (Retrieval-Augmented Generation) doesn't fix this either, because dumping raw chunks into a prompt still leaves the model free to summarize, blur, and paraphrase whatever it wants.

I wanted to see what happens when you treat the problem differently: what if the AI literally cannot generate Quranic text? What if the agent only has access to verified, structured records in Sanity, and conflicting historical opinions are modeled cleanly as data rather than smoothed over?

That is what Quran Sanity Agent is built to do.

Quran Sanity Agent is a bilingual (Arabic & English) web research workspace where every single verse, translation, and scholarly commentary is anchored to an immutable record in Sanity.

The app is live, publicly accessible, and backed by a hosted Sanity Studio:

Inspect real-time Sanity Document IDs, physical book locators, and raw JSON payloads straight from the Content Lake.

Here are four questions you can paste into the live app to see the structured pipeline in action:

2:255 (or switch the UI to Arabic and type Ψ§Ω„Ψ¨Ω‚Ψ±Ψ© Ω’Ω₯Ω₯). ayah-2-255 in the Evidence Drawer.Compare interpretations of Al-Fatiha Basmalah Compare interpretations of Al-Asr What does the Quran say about justice even against oneself? The entire codebase is open-source and available on GitHub:

πŸ‘‰ github.com/OmarAfifi-CSE/quran-sanity-agent

The project is structured as a TypeScript monorepo:

web/: studio/: scripts/: This project is built around the idea that an agent is only as reliable as the structure behind its content.

Here is how Sanity handles every layer of the architecture:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   SANITY CONTENT LAKE                    β”‚
β”‚   β€’ 114 Surahs (Surah number, names, revelation type)    β”‚
β”‚   β€’ 6,236 Ayahs (Uthmani text, translation, keywords)    β”‚
β”‚   β€’ 6 Tafsir Authorities (Scholar, death year, school)   β”‚
β”‚   β€’ 12 Audited Interpretive Claims with primary excerpts β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚                             β”‚
    Exact Lookups (GROQ)          Semantic Queries (MCP)
             β”‚                             β”‚
             β–Ό                             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Deterministic Lake Fetch β”‚  β”‚ Sanity Context MCP Endpoint β”‚
β”‚  β€’ Sub-50ms response     β”‚  β”‚  β€’ 21,398 library chunks    β”‚
β”‚  β€’ Direct schema joins   β”‚  β”‚  β€’ Vector embeddings rank   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚                             β”‚
             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 NEXT.JS AGENT WORKSPACE                  β”‚
β”‚   β€’ Verifies all candidate IDs against Content Lake      β”‚
β”‚   β€’ Rejects AI notes that lack verbatim source quotes    β”‚
β”‚   β€’ Renders bilingual cards & Evidence Drawer            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

studio/schemaTypes/) Instead of generic blog or article schemas, Sanity Studio manages structured Quranic and classical commentary data:

surah: ayah: tafsirSource: athari, juridical, rational, linguistic). interpretiveClaim: primaryExcerpt), the physical book locator ( sourceLocator), the divergence classification ( contradictory, complementary, consensus), and editorial status. sourceEdition & libraryChunk: One of the most practical things about Sanity Studio is how easily you can customize the Desk Structure to enforce editorial discipline.

In [studio/deskStructure.ts], I added a custom "Needs source review" filter:

If an editor enters a new claim but forgets the primary book excerpt, the exact source URL, or the reviewer sign-off, Sanity immediately catches it and moves it into this review queue.

More importantly, the Next.js agent's GROQ queries strictly filter for reviewStatus in ["source_checked", "reviewed"]. If a claim hasn't passed the editorial gate, the AI agent is physically unable to see it or use it in an answer.

While exact verse numbers (e.g. 2:255) are resolved instantly via deterministic GROQ queries, thematic questions (e.g. "What does the Quran say about justice?") require semantic understanding.

To handle this, I pointed Sanity Context at the imported library of 21,398 chunks and enabled Content Lake embeddings:

qkca243t production https://api.sanity.io/v1/context/organizations/o831wcpb9/mcp/quran-evidence-mcp Building this project made one thing very clear:

The solution to AI hallucination in high-stakes domains isn't "better prompts" or larger models. It's structured content.

When you treat texts as unstructured strings dumped into a vector database, the AI is always one step away from fabricating an answer. But when you model your domain properlyβ€”distinguishing chapters from verses, authorities from editions, and consensus from disagreementβ€”the AI stops guessing and starts acting as an interface to verified knowledge.

Sanity was uniquely suited for this: having schemas, the Content Lake, GROQ, and the Context MCP in one unified ecosystem meant I could build a zero-hallucination agent that remains completely transparent with every answer it gives.

Check out the live project at quran-sanity.omar-afifi.com and explore the code on GitHub.

── more in #ai-agents 4 stories Β· sorted by recency
── more on @sanity 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/building-an-agent-th…] indexed:0 read:4min 2026-10-04 Β· β€”