cd /news/ai-agents/a-langgraph-sql-agent-that-only-sees… · home › topics › ai-agents › article
[ARTICLE · art-165142] src=ainexusdaily.vercel.app ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

A LangGraph SQL agent that only sees the tables it needs

A new LangGraph example in the open-source schemagate project cuts schema tokens sent to the model by 68% to 78% on a bundled 42-table demo database, sending 489 to 706 tokens per question instead of 2,199, with all three test answers correct using Claude Haiku. The four-node agent uses a SchemagateRetriever to pick only the tables a question needs in an offline step with no model call, then writes one SELECT, runs it, and returns a one-sentence answer; on databases with 50 or more tables the saving reaches about 91%. Schemagate, which is Apache-2.0 and listed in LangChain's official retriever integrations, ranks #1 on the BIRD Mini-Dev leaderboard across SQLite, PostgreSQL and MySQL, and the example installs via pip install langchain-schemagate langgraph langchain-anthropic tiktoken.

read1 min views4 publishedNov 6, 2026
A LangGraph SQL agent that only sees the tables it needs
Image: Ainexusdaily (auto-discovered)

Most text-to-SQL agents paste the whole schema into every prompt. On a real database, most of it is tables the question never touches, and you pay for them on every call. I added a small LangGraph example to schemagate that does it differently. It has four nodes: select_schema: SchemagateRetriever p

icks the few tables the question needs. This step runs offline, with no model call. write_sql: the model writes one SELECT using only those tables. run_sql: the agent runs the query.

If it fails, the error goes back to the model once. answer: the model answers in one sentence from the returned rows. On the bundled 42-table demo database: Question Schema tokens sent Which customers owe us money? 489 vs 2,199 (78% fewer) How many orders did each carrier ship? 706 vs 2,199 (68% fewer) Which products are below their reorder level, and in which warehouse? 563 vs 2,199 (74% fewer) All three answers were correct with Claude Haiku. On databases with 50+ tables the saving reaches about 91%. The selection also respects roles: a table the caller can't read never appears in the prompt.

pip install langchain-schemagate langgraph langchain-anthropic tiktoken python examples/langgraph_sql_agent.py To use your own database, swap demo_catalog() for Catalog().bootstrap("postgresql://..."). schemagate is #1 on the BIRD Mini-Dev leaderboard (SQLite, PostgreSQL, MySQL), is listed in LangChain's official retriever integrations, and is Apache-2.0. Example: examples/langgraph_sql_agent.py

Key Takeaways #

  • •This step runs offline, with no model call.
  • •This story was reported by Dev.to , covering developments in thedev space.
  • •AI advancements continue to reshape industries — read the full article on Dev.to for complete coverage.

📖 Continue reading the full article:

Read Full Article on Dev.to →

── more in #ai-agents 4 stories · sorted by recency
── more on @langgraph 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/a-langgraph-sql-agen…] indexed:0 read:1min 2026-11-06 · —