This is a submission for the Sanity Challenge, Path One: Ship an Agent That Queries Real Content
What I Built
When you give money to a community foundation, where does it go next? Often to another intermediary, such as a donor-advised fund sponsor or another foundation, before it reaches an organization that runs programs. That path is public in IRS Form 990 filings, but nobody reads Schedule I tables for fun.
Clearfund is a chat agent that answers questions like "If I donate to Silicon Valley Community Foundation, how many hops before it reaches a program?" Each answer comes with:
- a chain diagram showing each hop, sized by grant amount
- a grant table with amounts, years and purposes
- a link on every grant to the original IRS filing, so you can check the claim yourself
It is meant as a neutral transparency tool: here are the sourced facts, you decide what they mean.
Demo
https://clearfund-kappa.vercel.app/
No login required. Open the link and ask a question, or click one of the suggested prompts on the first screen.
Questions to try:
- If I donate to Silicon Valley Community Foundation, how many hops before it reaches a program?
- Which organizations both receive grants and re-grant them?
- Who are the biggest funders of Navigation Charitable Fund?
- What grants did Silicon Valley Community Foundation make in 2023?
- Which grants went to CZ Biohub?
- Where does money from Fidelity Charitable go?
Each answer shows a chain diagram or grant table, and every grant links to its IRS filing.
Every answer cites a source number like Source: 202413129349304911 or a direct link. That is the ID of the IRS tax return the grant was taken from.
Code
https://github.com/Krishaant003/clearfund
Architecture
Browser (chat UI) Next.js server: POST /api/chat
├─ question ───────────────────────► Vercel AI SDK streamText
└─ chain diagram + grant table ◄── ├─ Gemini (Any LLM) (decides which tools to call)
(IRS filing link per grant) │
├─ Context MCP tools ─────► Sanity Context MCP endpoint
│ background on orgs └─ Knowledge Base (10 entries)
│ built from ┐
└─ Custom GROQ tools ─────► Sanity dataset ◄──┘
traceChain organization, grant
getGrantsByFunder (grant → funder/recipient
getGrantsByRecipient references, sourceObjectId)
findIntermediaries
The chain diagram and grant table are drawn from the GROQ tools' structured results, not from the model's wording.
How I Used Sanity
Clearfund uses Sanity in three layers: structured content, a Context Knowledge Base, and direct GROQ queries. The agent combines the last two on every question.
1. Structured content: the data model
I modeled open IRS Form 990 data as two document types:
-
organization: EIN, name, state and NTEE code. -
grant: references to a funder and a recipient organization, plus the amount, tax year, purpose, match tier and the IRSsourceObjectIdof the filing the grant came from.
Because grants point at organizations by reference, "who did this foundation fund?" and "who funded this organization?" are exact lookups, not text matching. The dataset has 64 grants and about 40 organizations, all seeded from public filings, and it is public (project vnc5zsa7).
2. Sanity Context: a Knowledge Base served over MCP
I pointed a Context Knowledge Base at the production dataset (104 documents) with a GROQ query that resolves each grant's funder and recipient, so every source record is self-contained: names, EINs, amount, year and filing ID together. The build organized them into 10 entries, such as community-foundation pass-through grants and donor-advised-fund flows. Entries I checked kept exact amounts, EINs and sourceObjectIds, and each one links back to its source records.
The agent connects to the Knowledge Base through the Context MCP endpoint. It reads the entry outline with initial_context, then uses knowledge_base_search and knowledge_base_read to find and open the entries it needs. This gives it background on who the organizations are and how money moves between them.
The build also flagged five conflicts, all the same organization EIN written two ways.I resolved them in favor of the plain form, and that decision carries into future builds.
3. Direct GROQ queries: exact answers and the hop chain
For anything that must be exactly right, the agent also calls four custom tools that run GROQ queries against the dataset. These are tools in the Vercel AI SDK, separate from the MCP endpoint:
| Tool | What its GROQ query does |
|---|---|
traceChain |
Starts at an EIN, takes the largest grant out of that organization, follows the recipient reference, and repeats up to a hop limit. It returns each hop with its sourceObjectId. |
getGrantsByFunder |
All grants where an organization is the funder, largest first. |
getGrantsByRecipient |
All grants where an organization is the recipient. |
findIntermediaries |
Organizations that appear as both a recipient and a funder: the re-granting intermediaries. |
traceChain is what answers "how many hops?". Its structured output is also what the UI draws as the chain diagram and the grant table, and each grant links to its IRS filing. Those visuals come from query results, not from the model's wording.
How the two work together
The Knowledge Base tells the agent what kind of organization it is looking at and where to look. The GROQ tools supply the exact figures and the chain. The agent is told to treat the grant tools as the source of facts and use the Knowledge Base for context.
I chose that split after testing the alternative. Answering from the Knowledge Base alone, the agent said Navigation Charitable Fund passes funds onward. The structured data shows no grants out of it, so the chain ends there at one hop. Following references with a query gets that right, which a prose summary did not.
Sanity Project Details
Project ID: vnc5zsa7 (dataset: production).
The grant and organization schemas are in the repo under sanity/schemas/. https://github.com/Krishaant003/clearfund/tree/master/sanity/schemas
Top comments (0)