Skip to main content
DatabaseContextProvider routes database reads and writes through separate SQLAlchemy engines. It exposes query_database for reads and update_database for writes.

Prerequisites

Example

Both engines are required. The provider routes read requests to readonly_engine and write requests to sql_engine. Configure readonly_engine with database credentials restricted to SELECT operations and the allowed schemas. The schema parameter controls table discovery, not authorization for arbitrary SQL.

Provider Params

Tools Exposed

Privilege Separation

The read and write sub-agents use separate database connections:
The separate engines route each tool to the intended connection. Database roles enforce the boundary. Grant the reader role SELECT-only access to the required schemas, and grant the writer role only the write permissions it needs. The schema parameter helps the agent discover tables and columns but does not block cross-schema SQL.

Multiple Databases

Use different id values to expose multiple databases:

Read-only Tool Surface

write=False removes update_database from the agent’s tools. It does not change the permissions of readonly_engine, so keep that engine restricted at the database level.

Cookbook

Database Context Provider

Read/write with separate engines