DEV Community

Mads Hansen
Mads Hansen

Posted on

Your AI database agent needs query routing before SQL

Not every database question should hit the same source.

“What did revenue do last quarter?” can use a warehouse.

“Is this customer currently blocked?” may need live operational data.

“Export every user who churned” may need approval before it runs at all.

AI database agents need query routing before SQL generation becomes execution.

Routing is part of safety

Production systems are not one database-shaped box.

There are:

  • primaries
  • read replicas
  • reporting warehouses
  • materialized views
  • caches
  • audit tables
  • third-party APIs

They have different freshness, permissions, latency, and risk profiles.

A good MCP database layer should choose the safest valid path for the question.

Routing should consider intent:

  • operational status may require live data
  • trend analysis may belong on a warehouse
  • customer support answers may need tenant-scoped approved views
  • large exports may require dry-run and approval
  • unclear write requests should fail closed

Longer version: Query routing for AI database agents

The practical rule:

Before an agent asks “what SQL should I run?”, it should ask “which source is safe and correct for this question?”

Top comments (0)