Dialects¶
Each dialect module wires up the tools and prompt fragment for a specific database backend.
deep_db_agents.dialects ¶
Imports all dialects to populate the registry when the package is imported.
The side-effect import is intentional: each module registers its own dialect via the
@register decorator.
duckdb ¶
DuckDB dialect.
DuckDBDialect ¶
DuckDBDialect()
Bases: FileSqlDialect
Agent specialized on DuckDB.
Initializes the dialect with an empty data-lake connection cache.
Source code in src/deep_db_agents/dialects/duckdb/dialect.py
34 35 36 37 38 39 40 | |
system_prompt ¶
system_prompt() -> str
Returns the DuckDB-specific system prompt.
Returns:
| Type | Description |
|---|---|
str
|
The system prompt text for the DuckDB agent. |
Source code in src/deep_db_agents/dialects/duckdb/dialect.py
42 43 44 45 46 47 48 | |
dialect ¶
Full DuckDB dialect (duckdb package).
DuckDB is a file-based analytical SQL database: the URL duckdb://<path> indicates the
file (SQLAlchemy style: duckdb:///rel.duckdb relative to the working dir,
duckdb:////abs.duckdb absolute) or a folder (trailing slash, e.g. duckdb:///lake/)
interpreted as a data lake: the parquet/csv/json files inside it are exposed as tables. It
reuses SqlDialect's logic; the execution timeout is enforced by FileSqlDialect's
watchdog.
In data lake mode the views are created only once per dialect instance (a snapshot of the
folder taken on the first call). Warning: with duckdb://:memory: every tool call opens a
brand-new, empty database (the connection is per-call).
DuckDBDialect ¶
DuckDBDialect()
Bases: FileSqlDialect
Agent specialized on DuckDB.
Initializes the dialect with an empty data-lake connection cache.
Source code in src/deep_db_agents/dialects/duckdb/dialect.py
34 35 36 37 38 39 40 | |
system_prompt ¶
system_prompt() -> str
Returns the DuckDB-specific system prompt.
Returns:
| Type | Description |
|---|---|
str
|
The system prompt text for the DuckDB agent. |
Source code in src/deep_db_agents/dialects/duckdb/dialect.py
42 43 44 45 46 47 48 | |
prompt ¶
Generic system prompt for the DuckDB-specialized agent.
tools ¶
Driver-specific helpers for DuckDB (duckdb package).
connect_datalake ¶
connect_datalake(folder: str)
Opens an in-memory DuckDB connection with a view for each data file in the folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder
|
str
|
Path to the data-lake folder to expose as tables. |
required |
Returns:
| Type | Description |
|---|---|
|
An in-memory DuckDB connection with one view registered per recognized data file. |
Source code in src/deep_db_agents/dialects/duckdb/tools.py
100 101 102 103 104 105 106 107 108 109 110 111 112 | |
connect_file ¶
connect_file(path: str, *, read_only: bool = True)
Opens a connection to a DuckDB file.
read_only=True allows concurrent connections to the same file (needed when tool calls
run in parallel): in write mode DuckDB holds an exclusive lock. Query duration is bounded
separately by the watchdog calling interrupt() (see FileSqlDialect).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the DuckDB database file. |
required |
read_only
|
bool
|
If True, opens the connection in read-only mode. |
True
|
Returns:
| Type | Description |
|---|---|
|
An open DuckDB connection. |
Source code in src/deep_db_agents/dialects/duckdb/tools.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
estimate_rows ¶
estimate_rows(cursor, sql: str) -> int
Estimates the row count by reading the cardinality from the EXPLAIN plan.
This is best-effort: any failure to run or parse EXPLAIN results in an estimate of 0
rather than raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cursor
|
An open DuckDB cursor. |
required | |
sql
|
str
|
The SELECT statement to estimate. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The largest cardinality estimate found in the EXPLAIN plan text, or 0 if none could |
int
|
be extracted. |
Source code in src/deep_db_agents/dialects/duckdb/tools.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
register_datalake_views ¶
register_datalake_views(con, folder: str) -> list[str]
Creates a view for each data file (parquet/csv/json) in folder.
Exposes the files as queryable tables with regular SQL, so the SQL dialect's tools work unmodified. Each view is named after the (sanitized) file name without its extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
con
|
An open DuckDB connection on which to create the views. |
required | |
folder
|
str
|
Path to the data-lake folder to scan for data files. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The list of created view names. |
Source code in src/deep_db_agents/dialects/duckdb/tools.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
elasticsearch ¶
Elasticsearch dialect.
ElasticsearchDialect ¶
ElasticsearchDialect()
Bases: SearchDialect
Agent specialized on Elasticsearch.
Access is restricted to the index(es) configured in credential["index"]
(single name, CSV, or a * pattern); every tool inherited from
:class:SearchDialect validates the requested index against this scope before
querying the cluster.
Source code in src/deep_db_agents/dialects/search_base.py
171 172 173 174 175 | |
system_prompt ¶
system_prompt() -> str
Return the Elasticsearch-specific system prompt.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The system prompt text for the Elasticsearch agent. |
Source code in src/deep_db_agents/dialects/elasticsearch/dialect.py
31 32 33 34 35 36 37 | |
dialect ¶
Complete Elasticsearch dialect (official elasticsearch driver).
Reuses the entire tool logic from :mod:..search_base (shared by Elasticsearch and
OpenSearch); this module only provides the driver-specific connection opening.
ElasticsearchDialect ¶
ElasticsearchDialect()
Bases: SearchDialect
Agent specialized on Elasticsearch.
Access is restricted to the index(es) configured in credential["index"]
(single name, CSV, or a * pattern); every tool inherited from
:class:SearchDialect validates the requested index against this scope before
querying the cluster.
Source code in src/deep_db_agents/dialects/search_base.py
171 172 173 174 175 | |
system_prompt ¶
system_prompt() -> str
Return the Elasticsearch-specific system prompt.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The system prompt text for the Elasticsearch agent. |
Source code in src/deep_db_agents/dialects/elasticsearch/dialect.py
31 32 33 34 35 36 37 | |
prompt ¶
Generic system prompt for the Elasticsearch-specialized agent.
tools ¶
Driver-specific helpers for Elasticsearch (official elasticsearch driver).
connect ¶
connect(conn: ConnectionConfig, *, request_timeout: int | None = None) -> Any
Open an Elasticsearch client from the given credentials.
The driver is imported lazily so the package can be imported without the
elasticsearch extra installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection configuration with host, port, and credentials. Recognized
|
required |
request_timeout
|
int | None
|
Optional request timeout in seconds; forwarded to the client only if positive. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
An initialized |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the |
Source code in src/deep_db_agents/dialects/elasticsearch/tools.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
mariadb ¶
MariaDB dialect.
MariaDBDialect ¶
Bases: MySQLDialect
Agent specialized on MariaDB.
system_prompt ¶
system_prompt() -> str
Return the MariaDB-specific system prompt.
Returns:
| Type | Description |
|---|---|
str
|
The full system prompt text for the MariaDB agent. |
Source code in src/deep_db_agents/dialects/mariadb/dialect.py
22 23 24 25 26 27 28 | |
dialect ¶
Full MariaDB dialect.
MariaDB is compatible with the MySQL protocol, so it reuses the pymysql driver and most
of MySQLDialect's logic. It differs in the query timeout mechanism: MariaDB uses the
max_statement_time session variable (in seconds), while MySQL uses MAX_EXECUTION_TIME
(in milliseconds).
MariaDBDialect ¶
Bases: MySQLDialect
Agent specialized on MariaDB.
system_prompt ¶
system_prompt() -> str
Return the MariaDB-specific system prompt.
Returns:
| Type | Description |
|---|---|
str
|
The full system prompt text for the MariaDB agent. |
Source code in src/deep_db_agents/dialects/mariadb/dialect.py
22 23 24 25 26 27 28 | |
prompt ¶
Generic system prompt for the MariaDB-specialized agent.
mongodb ¶
MongoDB dialect (stub).
MongoDBDialect ¶
MongoDBDialect()
Bases: DbDialect
Agent specialized on MongoDB.
Source code in src/deep_db_agents/dialects/mongodb/dialect.py
34 35 36 | |
close ¶
close() -> None
Closes the reused MongoClient. Call at the end of the agent's lifetime.
Source code in src/deep_db_agents/dialects/mongodb/dialect.py
41 42 43 | |
dialect ¶
Full MongoDB dialect (pymongo driver).
Carries the context-management principles over to the document model: exploration of collections and inferred schema, counting before extraction, read-only find/aggregate with forced limit and projection, and file materialization of large results.
MongoDBDialect ¶
MongoDBDialect()
Bases: DbDialect
Agent specialized on MongoDB.
Source code in src/deep_db_agents/dialects/mongodb/dialect.py
34 35 36 | |
close ¶
close() -> None
Closes the reused MongoClient. Call at the end of the agent's lifetime.
Source code in src/deep_db_agents/dialects/mongodb/dialect.py
41 42 43 | |
prompt ¶
Generic system prompt for the agent specialized on MongoDB.
tools ¶
Driver-specific helpers for MongoDB (pymongo).
connect ¶
connect(conn: ConnectionConfig, *, socket_timeout_ms: int | None = None)
Opens a MongoClient from the credentials. Lazy import of the driver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection configuration (host, port, credentials). |
required |
socket_timeout_ms
|
int | None
|
Timeout enforced on network operations (socket read/write):
without it, a |
None
|
Returns:
| Type | Description |
|---|---|
|
A connected |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the |
Source code in src/deep_db_agents/dialects/mongodb/tools.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
docs_to_table ¶
docs_to_table(docs: list[dict]) -> tuple[list[str], list[list[Any]]]
Converts heterogeneous documents into (columns, rows) for file materialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs
|
list[dict]
|
The list of documents to convert. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list[str], list[list[Any]]]
|
A tuple of (column names, row values). |
Source code in src/deep_db_agents/dialects/mongodb/tools.py
175 176 177 178 179 180 181 182 183 184 | |
ensure_read_only_filter ¶
ensure_read_only_filter(filter_: Any) -> Any
Validates a filter/projection: no server-side JS operator ($where/$function).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_
|
Any
|
The filter or projection document to validate. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The same value, unchanged, if validation passes. |
Raises:
| Type | Description |
|---|---|
QueryNotAllowedError
|
If a forbidden operator is found. |
Source code in src/deep_db_agents/dialects/mongodb/tools.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
ensure_read_only_pipeline ¶
ensure_read_only_pipeline(pipeline: Any) -> list
Validates the pipeline: a list with no write stages ($out/$merge) nor JS operators,
at any depth (even nested in $facet/$lookup).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pipeline
|
Any
|
The aggregation pipeline to validate. |
required |
Returns:
| Type | Description |
|---|---|
list
|
The same pipeline, unchanged, if validation passes. |
Raises:
| Type | Description |
|---|---|
QueryNotAllowedError
|
If |
Source code in src/deep_db_agents/dialects/mongodb/tools.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
parse_json ¶
parse_json(text: str | None, *, what: str = 'argument') -> Any
Decodes JSON (extended, with ObjectId/date support) or returns an empty default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | None
|
The JSON string to decode, or |
required |
what
|
str
|
Description of the value being parsed, used in the error message. |
'argument'
|
Returns:
| Type | Description |
|---|---|
Any
|
The decoded value, or |
Raises:
| Type | Description |
|---|---|
QueryNotAllowedError
|
If |
Source code in src/deep_db_agents/dialects/mongodb/tools.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
mysql ¶
MySQL dialect.
MySQLDialect ¶
Bases: SqlDialect
Agent specialized on MySQL.
system_prompt ¶
system_prompt() -> str
Return the MySQL-specific system prompt.
Returns:
| Type | Description |
|---|---|
str
|
The full system prompt text for the MySQL agent. |
Source code in src/deep_db_agents/dialects/mysql/dialect.py
22 23 24 25 26 27 28 | |
dialect ¶
Full MySQL dialect (pymysql driver).
MySQLDialect ¶
Bases: SqlDialect
Agent specialized on MySQL.
system_prompt ¶
system_prompt() -> str
Return the MySQL-specific system prompt.
Returns:
| Type | Description |
|---|---|
str
|
The full system prompt text for the MySQL agent. |
Source code in src/deep_db_agents/dialects/mysql/dialect.py
22 23 24 25 26 27 28 | |
prompt ¶
Generic system prompt for the MySQL-specialized agent.
tools ¶
MySQL-specific driver helpers (pymysql).
connect ¶
connect(conn: ConnectionConfig, *, network_timeout_s: int | None = None)
Open a pymysql connection from credentials, with lazy driver import.
network_timeout_s enforces a timeout on socket read/write: without it, a query
whose socket stalls would hang forever (connect_timeout only covers connection
setup). It should be derived from guardrails.query_timeout_s.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection parameters (host, port, credentials, database). |
required |
network_timeout_s
|
int | None
|
Read/write socket timeout in seconds, or |
None
|
Returns:
| Type | Description |
|---|---|
|
An open pymysql connection. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the |
Source code in src/deep_db_agents/dialects/mysql/tools.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
estimate_rows ¶
estimate_rows(cursor, sql: str) -> int
Estimate the rows returned by sql using EXPLAIN (rows column).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cursor
|
DB-API cursor to run the |
required | |
sql
|
str
|
SQL query to estimate. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated row count, or 0 if it cannot be determined. |
Source code in src/deep_db_agents/dialects/mysql/tools.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
neo4j ¶
Neo4j dialect (stub).
Neo4jDialect ¶
Neo4jDialect()
Bases: DbDialect
Agent specialized on Neo4j.
Source code in src/deep_db_agents/dialects/neo4j/dialect.py
78 79 80 81 | |
close ¶
close() -> None
Closes the reused Neo4j Driver. Call at the end of the agent's lifetime.
Source code in src/deep_db_agents/dialects/neo4j/dialect.py
86 87 88 | |
dialect ¶
Full Neo4j dialect (official neo4j driver).
Carries the context-management principles over to the graph: exploration of labels,
relationship types and property keys, counting before extraction, execution of read-only
Cypher with a consumer-side forced limit, and file materialization of large results.
Queries run in read transactions (execute_read), which prevent server-side writes on
top of the clause whitelist.
Neo4jDialect ¶
Neo4jDialect()
Bases: DbDialect
Agent specialized on Neo4j.
Source code in src/deep_db_agents/dialects/neo4j/dialect.py
78 79 80 81 | |
close ¶
close() -> None
Closes the reused Neo4j Driver. Call at the end of the agent's lifetime.
Source code in src/deep_db_agents/dialects/neo4j/dialect.py
86 87 88 | |
prompt ¶
Generic system prompt for the agent specialized on Neo4j.
tools ¶
Driver-specific helpers for Neo4j (official neo4j driver).
connect ¶
connect(conn: ConnectionConfig, *, network_timeout_s: int | None = None)
Opens a Neo4j driver from the credentials. Lazy import of the driver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection configuration (host, port, credentials). |
required |
network_timeout_s
|
int | None
|
Client-side timeout (derived from
|
None
|
Returns:
| Type | Description |
|---|---|
|
A connected |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the |
Source code in src/deep_db_agents/dialects/neo4j/tools.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
ensure_read_only ¶
ensure_read_only(cypher: str) -> str
Validates that the Cypher is a single read-only statement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cypher
|
str
|
The raw Cypher statement submitted by the agent. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The stripped statement, if validation passes. |
Raises:
| Type | Description |
|---|---|
QueryNotAllowedError
|
If the statement is empty, contains multiple statements, or uses a forbidden write clause. |
Source code in src/deep_db_agents/dialects/neo4j/tools.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
quote_label ¶
quote_label(label: str) -> str
Escapes a Cypher label/identifier (doubled backticks).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The raw label/identifier to escape. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The label wrapped in backticks, with any internal backtick doubled. |
Prevents a label containing a backtick from escaping the quoting in
(n:\`label\`) and injecting Cypher.
Source code in src/deep_db_agents/dialects/neo4j/tools.py
62 63 64 65 66 67 68 69 70 71 72 73 74 | |
records_to_table ¶
records_to_table(keys: list[str], records: list[dict]) -> tuple[list[str], list[list[Any]]]
Converts Cypher records into (columns, rows) for file materialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys
|
list[str]
|
The result column names declared by the Cypher query. |
required |
records
|
list[dict]
|
The record data, one dict per row. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list[str], list[list[Any]]]
|
A tuple of (column names, row values). |
Unlike documents, the columns are the keys declared by the Cypher result (not the
union of keys); nodes/relationships/nested values are serialized.
Source code in src/deep_db_agents/dialects/neo4j/tools.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
opensearch ¶
OpenSearch dialect.
OpenSearchDialect ¶
OpenSearchDialect()
Bases: SearchDialect
Agent specialized on OpenSearch.
Access is restricted to the index(es) configured in credential["index"]
(single name, CSV, or a * pattern); every tool inherited from
:class:SearchDialect validates the requested index against this scope before
querying the cluster.
Source code in src/deep_db_agents/dialects/search_base.py
171 172 173 174 175 | |
system_prompt ¶
system_prompt() -> str
Return the OpenSearch-specific system prompt.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The system prompt text for the OpenSearch agent. |
Source code in src/deep_db_agents/dialects/opensearch/dialect.py
31 32 33 34 35 36 37 | |
dialect ¶
Complete OpenSearch dialect (official opensearch-py driver).
Reuses the entire tool logic from :mod:..search_base (shared by Elasticsearch and
OpenSearch); this module only provides the driver-specific connection opening.
OpenSearchDialect ¶
OpenSearchDialect()
Bases: SearchDialect
Agent specialized on OpenSearch.
Access is restricted to the index(es) configured in credential["index"]
(single name, CSV, or a * pattern); every tool inherited from
:class:SearchDialect validates the requested index against this scope before
querying the cluster.
Source code in src/deep_db_agents/dialects/search_base.py
171 172 173 174 175 | |
system_prompt ¶
system_prompt() -> str
Return the OpenSearch-specific system prompt.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The system prompt text for the OpenSearch agent. |
Source code in src/deep_db_agents/dialects/opensearch/dialect.py
31 32 33 34 35 36 37 | |
prompt ¶
Generic system prompt for the OpenSearch-specialized agent.
tools ¶
Driver-specific helpers for OpenSearch (official opensearch-py driver).
connect ¶
connect(conn: ConnectionConfig, *, request_timeout: int | None = None) -> Any
Open an OpenSearch client from the given credentials.
The driver is imported lazily so the package can be imported without the
opensearch extra installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection configuration with host, port, and credentials. Recognized
|
required |
request_timeout
|
int | None
|
Optional request timeout in seconds; forwarded to the client only if positive. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
An initialized |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the |
Source code in src/deep_db_agents/dialects/opensearch/tools.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
postgres ¶
Postgres dialect.
PostgresDialect ¶
Bases: SqlDialect
Agent specialized on PostgreSQL.
system_prompt ¶
system_prompt() -> str
Return the PostgreSQL-specific system prompt.
Returns:
| Type | Description |
|---|---|
str
|
The full system prompt text for the PostgreSQL agent. |
Source code in src/deep_db_agents/dialects/postgres/dialect.py
21 22 23 24 25 26 27 | |
dialect ¶
Full PostgreSQL dialect (psycopg 3 driver).
PostgresDialect ¶
Bases: SqlDialect
Agent specialized on PostgreSQL.
system_prompt ¶
system_prompt() -> str
Return the PostgreSQL-specific system prompt.
Returns:
| Type | Description |
|---|---|
str
|
The full system prompt text for the PostgreSQL agent. |
Source code in src/deep_db_agents/dialects/postgres/dialect.py
21 22 23 24 25 26 27 | |
prompt ¶
Generic system prompt for the PostgreSQL-specialized agent.
tools ¶
PostgreSQL-specific driver helpers (psycopg 3).
connect ¶
connect(conn: ConnectionConfig, *, network_timeout_s: int | None = None)
Open a psycopg connection from credentials, with lazy driver import.
network_timeout_s configures TCP keepalives so that a connection whose peer is dead
(socket hanging, no data) is torn down within ~network_timeout_s, instead of waiting
indefinitely. It should be derived from guardrails.query_timeout_s.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection parameters (host, port, credentials, database). |
required |
network_timeout_s
|
int | None
|
Idle time in seconds before keepalive probing starts, or
|
None
|
Returns:
| Type | Description |
|---|---|
|
An open psycopg connection. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the |
Source code in src/deep_db_agents/dialects/postgres/tools.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
estimate_rows ¶
estimate_rows(cursor, sql: str) -> int
Estimate rows via EXPLAIN (FORMAT JSON), reading Plan Rows of the root node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cursor
|
DB-API cursor to run the |
required | |
sql
|
str
|
SQL query to estimate. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated row count, or 0 if it cannot be determined. |
Source code in src/deep_db_agents/dialects/postgres/tools.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
search_base ¶
Shared base for document 'search' dialects (Elasticsearch, OpenSearch).
elasticsearch-py and opensearch-py expose the same REST API (cat.indices,
indices.get_mapping, count, search), so the entire tool logic is shared here;
each concrete dialect implements only the driver-specific connection opening (_connect).
Unlike the SQL dialects there is no need for a statement whitelist: the tools only use
read endpoints (_search, _count, _cat, _mapping), never write or delete
endpoints (_bulk, _update, _delete_by_query...) — the main guardrail is
therefore the restriction on queryable indices, configured via the index key of the
credentials (single name, CSV list or * pattern).
SearchDialect ¶
SearchDialect()
Bases: DbDialect
Base for document search engine dialects (Elasticsearch, OpenSearch).
Initializes the dialect with an empty, lazily-populated client cache.
Source code in src/deep_db_agents/dialects/search_base.py
171 172 173 174 175 | |
build_tools ¶
build_tools(conn: ConnectionConfig, guardrails: GuardrailConfig, materialize_enable: bool = False) -> Sequence[BaseTool]
Builds the LangChain tools exposed to the agent for this search dialect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection parameters injected into the tool closures. |
required |
guardrails
|
GuardrailConfig
|
Guardrail configuration (limits, timeout, budget) enforced by every tool. |
required |
materialize_enable
|
bool
|
Whether to also expose the |
False
|
Returns:
| Type | Description |
|---|---|
Sequence[BaseTool]
|
The sequence of tools: |
Sequence[BaseTool]
|
|
Sequence[BaseTool]
|
enabled, |
Source code in src/deep_db_agents/dialects/search_base.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
close ¶
close() -> None
Closes the reused ES/OS client. Call this at the end of the agent's lifetime.
Source code in src/deep_db_agents/dialects/search_base.py
189 190 191 | |
allowed_index_pattern ¶
allowed_index_pattern(conn: ConnectionConfig) -> str
Returns the index pattern/CSV the agent may operate on, from credentials (default *).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection parameters whose |
required |
Returns:
| Type | Description |
|---|---|
str
|
The configured index pattern/CSV, or |
Source code in src/deep_db_agents/dialects/search_base.py
45 46 47 48 49 50 51 52 53 54 55 | |
hits_to_table ¶
hits_to_table(hits: list[dict]) -> tuple[list[str], list[list[Any]]]
Converts search hits into (columns, rows) for materialization to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hits
|
list[dict]
|
The raw list of hit objects returned by a search. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
A tuple of (column names, row values). Columns are the union of |
list[list[Any]]
|
plus |
Source code in src/deep_db_agents/dialects/search_base.py
141 142 143 144 145 146 147 148 149 150 151 | |
parse_aggs ¶
parse_aggs(value: str | dict) -> dict
Decodes the aggs clause (JSON), which must be a non-empty object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | dict
|
The |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The decoded |
Raises:
| Type | Description |
|---|---|
QueryNotAllowedError
|
If |
Source code in src/deep_db_agents/dialects/search_base.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
parse_query ¶
parse_query(text: str | None, *, what: str = 'query') -> dict
Decodes the Query DSL clause (JSON), or returns match_all if absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | None
|
The raw JSON text of the Query DSL clause, or |
required |
what
|
str
|
Label used in the error message if parsing fails. |
'query'
|
Returns:
| Type | Description |
|---|---|
dict
|
The decoded query clause as a dict, or |
Raises:
| Type | Description |
|---|---|
QueryNotAllowedError
|
If |
Source code in src/deep_db_agents/dialects/search_base.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
resolve_index ¶
resolve_index(requested: str | None, allowed: str) -> str
Validates the requested index against the allowed pattern, raising on violation.
allowed can be a single name, a CSV list or a * pattern. If requested is
None, allowed is used directly (pattern/CSV expansion is left to the driver). If
requested is given, every CSV element of it must match at least one allowed pattern,
otherwise the request is rejected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requested
|
str | None
|
The index/indices requested by the agent, or |
required |
allowed
|
str
|
The configured allowed index pattern/CSV. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The index/indices to actually query. |
Raises:
| Type | Description |
|---|---|
QueryNotAllowedError
|
If a requested index does not match any allowed pattern. |
Source code in src/deep_db_agents/dialects/search_base.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
sql_base ¶
Shared base for SQL dialects (MySQL, Postgres).
Implements the SQL tools exactly once — schema exploration, counting, sampling, query execution with guardrails and materialization — delegating the driver-specific part (connection, row estimation via EXPLAIN, timeout, quoting) to abstract methods. The SQL drivers used (pymysql, psycopg) are both DB-API 2.0, so the execution logic is shared.
FileSqlDialect ¶
Bases: SqlDialect
Base for file-based SQL dialects (SQLite, DuckDB).
These engines have no server-side statement_timeout: the execution timeout is
enforced by a watchdog that calls connection.interrupt() from a separate thread past
query_timeout_s, so a long or hung query gets interrupted instead of freezing the
whole tool node when tool calls run in parallel.
is_directory
staticmethod
¶
is_directory(conn: ConnectionConfig) -> bool
Checks whether the URL points to a folder (trailing slash or existing directory).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection parameters whose |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the URL path is a directory (or has a trailing slash), False otherwise. |
Source code in src/deep_db_agents/dialects/sql_base.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | |
resolve_path
staticmethod
¶
resolve_path(path: str | None) -> str
Resolves the DB path relative to the working dir (:memory: passes through).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | None
|
The raw path from the connection URL, or |
required |
Returns:
| Type | Description |
|---|---|
str
|
The absolute, expanded path, or |
Source code in src/deep_db_agents/dialects/sql_base.py
482 483 484 485 486 487 488 489 490 491 492 493 494 | |
SqlDialect ¶
Bases: DbDialect
Abstract dialect for relational databases with a DB-API 2.0 interface.
build_tools ¶
build_tools(conn: ConnectionConfig, guardrails: GuardrailConfig, materialize_enable: bool = False) -> Sequence[BaseTool]
Builds the LangChain tools exposed to the agent for this SQL dialect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection parameters injected into the tool closures. |
required |
guardrails
|
GuardrailConfig
|
Guardrail configuration (limits, timeout, allowed statements, budget) enforced by every tool. |
required |
materialize_enable
|
bool
|
Whether to also expose the |
False
|
Returns:
| Type | Description |
|---|---|
Sequence[BaseTool]
|
The sequence of tools: |
Sequence[BaseTool]
|
|
Source code in src/deep_db_agents/dialects/sql_base.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
sqlite ¶
SQLite dialect.
SQLiteDialect ¶
Bases: FileSqlDialect
Agent specialized on SQLite.
system_prompt ¶
system_prompt() -> str
Returns the SQLite-specific system prompt.
Returns:
| Type | Description |
|---|---|
str
|
The system prompt text for the SQLite agent. |
Source code in src/deep_db_agents/dialects/sqlite/dialect.py
32 33 34 35 36 37 38 | |
dialect ¶
Full SQLite dialect (stdlib sqlite3 module).
SQLite is a file-based SQL database: the URL sqlite://<path> indicates the file
(SQLAlchemy style: sqlite:///rel.db relative to the working dir, sqlite:////abs.db
absolute, sqlite://:memory: in memory). It reuses all of SqlDialect's logic
(DB-API 2.0); the execution timeout is enforced by FileSqlDialect's watchdog because
SQLite has no native statement_timeout. File connections are opened read-only
(mode=ro), a defense-in-depth measure on top of the statement whitelist.
Warning: with :memory: every tool call opens a brand-new, empty database (the connection
is per-call): useful only for smoke tests, not for data that must survive across calls.
SQLiteDialect ¶
Bases: FileSqlDialect
Agent specialized on SQLite.
system_prompt ¶
system_prompt() -> str
Returns the SQLite-specific system prompt.
Returns:
| Type | Description |
|---|---|
str
|
The system prompt text for the SQLite agent. |
Source code in src/deep_db_agents/dialects/sqlite/dialect.py
32 33 34 35 36 37 38 | |
prompt ¶
Generic system prompt for the SQLite-specialized agent.
tools ¶
Driver-specific helpers for SQLite (stdlib sqlite3 module).
connect ¶
connect(path: str, *, busy_timeout_s: int = 10, read_only: bool = False)
Opens a SQLite connection.
busy_timeout_s is the wait timeout on a locked database (the timeout parameter of
sqlite3.connect); query execution duration is bounded separately by a watchdog calling
interrupt() (see FileSqlDialect). check_same_thread=False allows the watchdog
thread to call interrupt() on the connection.
read_only=True opens the file in read-only mode (URI ?mode=ro), so that even a
bypass of the keyword whitelist still cannot write to the database (defense in depth).
This does not apply to :memory:, which remains writable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the SQLite database file, or |
required |
busy_timeout_s
|
int
|
Seconds to wait on a locked database before giving up. |
10
|
read_only
|
bool
|
If True, opens the file in read-only mode via a |
False
|
Returns:
| Type | Description |
|---|---|
|
An open |
Source code in src/deep_db_agents/dialects/sqlite/tools.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
SQL base¶
deep_db_agents.dialects.sql_base ¶
Shared base for SQL dialects (MySQL, Postgres).
Implements the SQL tools exactly once — schema exploration, counting, sampling, query execution with guardrails and materialization — delegating the driver-specific part (connection, row estimation via EXPLAIN, timeout, quoting) to abstract methods. The SQL drivers used (pymysql, psycopg) are both DB-API 2.0, so the execution logic is shared.
FileSqlDialect ¶
Bases: SqlDialect
Base for file-based SQL dialects (SQLite, DuckDB).
These engines have no server-side statement_timeout: the execution timeout is
enforced by a watchdog that calls connection.interrupt() from a separate thread past
query_timeout_s, so a long or hung query gets interrupted instead of freezing the
whole tool node when tool calls run in parallel.
is_directory
staticmethod
¶
is_directory(conn: ConnectionConfig) -> bool
Checks whether the URL points to a folder (trailing slash or existing directory).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection parameters whose |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the URL path is a directory (or has a trailing slash), False otherwise. |
Source code in src/deep_db_agents/dialects/sql_base.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | |
resolve_path
staticmethod
¶
resolve_path(path: str | None) -> str
Resolves the DB path relative to the working dir (:memory: passes through).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | None
|
The raw path from the connection URL, or |
required |
Returns:
| Type | Description |
|---|---|
str
|
The absolute, expanded path, or |
Source code in src/deep_db_agents/dialects/sql_base.py
482 483 484 485 486 487 488 489 490 491 492 493 494 | |
SqlDialect ¶
Bases: DbDialect
Abstract dialect for relational databases with a DB-API 2.0 interface.
build_tools ¶
build_tools(conn: ConnectionConfig, guardrails: GuardrailConfig, materialize_enable: bool = False) -> Sequence[BaseTool]
Builds the LangChain tools exposed to the agent for this SQL dialect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection parameters injected into the tool closures. |
required |
guardrails
|
GuardrailConfig
|
Guardrail configuration (limits, timeout, allowed statements, budget) enforced by every tool. |
required |
materialize_enable
|
bool
|
Whether to also expose the |
False
|
Returns:
| Type | Description |
|---|---|
Sequence[BaseTool]
|
The sequence of tools: |
Sequence[BaseTool]
|
|
Source code in src/deep_db_agents/dialects/sql_base.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
Search base¶
deep_db_agents.dialects.search_base ¶
Shared base for document 'search' dialects (Elasticsearch, OpenSearch).
elasticsearch-py and opensearch-py expose the same REST API (cat.indices,
indices.get_mapping, count, search), so the entire tool logic is shared here;
each concrete dialect implements only the driver-specific connection opening (_connect).
Unlike the SQL dialects there is no need for a statement whitelist: the tools only use
read endpoints (_search, _count, _cat, _mapping), never write or delete
endpoints (_bulk, _update, _delete_by_query...) — the main guardrail is
therefore the restriction on queryable indices, configured via the index key of the
credentials (single name, CSV list or * pattern).
SearchDialect ¶
SearchDialect()
Bases: DbDialect
Base for document search engine dialects (Elasticsearch, OpenSearch).
Initializes the dialect with an empty, lazily-populated client cache.
Source code in src/deep_db_agents/dialects/search_base.py
171 172 173 174 175 | |
build_tools ¶
build_tools(conn: ConnectionConfig, guardrails: GuardrailConfig, materialize_enable: bool = False) -> Sequence[BaseTool]
Builds the LangChain tools exposed to the agent for this search dialect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection parameters injected into the tool closures. |
required |
guardrails
|
GuardrailConfig
|
Guardrail configuration (limits, timeout, budget) enforced by every tool. |
required |
materialize_enable
|
bool
|
Whether to also expose the |
False
|
Returns:
| Type | Description |
|---|---|
Sequence[BaseTool]
|
The sequence of tools: |
Sequence[BaseTool]
|
|
Sequence[BaseTool]
|
enabled, |
Source code in src/deep_db_agents/dialects/search_base.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
close ¶
close() -> None
Closes the reused ES/OS client. Call this at the end of the agent's lifetime.
Source code in src/deep_db_agents/dialects/search_base.py
189 190 191 | |
allowed_index_pattern ¶
allowed_index_pattern(conn: ConnectionConfig) -> str
Returns the index pattern/CSV the agent may operate on, from credentials (default *).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnectionConfig
|
Connection parameters whose |
required |
Returns:
| Type | Description |
|---|---|
str
|
The configured index pattern/CSV, or |
Source code in src/deep_db_agents/dialects/search_base.py
45 46 47 48 49 50 51 52 53 54 55 | |
hits_to_table ¶
hits_to_table(hits: list[dict]) -> tuple[list[str], list[list[Any]]]
Converts search hits into (columns, rows) for materialization to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hits
|
list[dict]
|
The raw list of hit objects returned by a search. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
A tuple of (column names, row values). Columns are the union of |
list[list[Any]]
|
plus |
Source code in src/deep_db_agents/dialects/search_base.py
141 142 143 144 145 146 147 148 149 150 151 | |
parse_aggs ¶
parse_aggs(value: str | dict) -> dict
Decodes the aggs clause (JSON), which must be a non-empty object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | dict
|
The |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The decoded |
Raises:
| Type | Description |
|---|---|
QueryNotAllowedError
|
If |
Source code in src/deep_db_agents/dialects/search_base.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
parse_query ¶
parse_query(text: str | None, *, what: str = 'query') -> dict
Decodes the Query DSL clause (JSON), or returns match_all if absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | None
|
The raw JSON text of the Query DSL clause, or |
required |
what
|
str
|
Label used in the error message if parsing fails. |
'query'
|
Returns:
| Type | Description |
|---|---|
dict
|
The decoded query clause as a dict, or |
Raises:
| Type | Description |
|---|---|
QueryNotAllowedError
|
If |
Source code in src/deep_db_agents/dialects/search_base.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
resolve_index ¶
resolve_index(requested: str | None, allowed: str) -> str
Validates the requested index against the allowed pattern, raising on violation.
allowed can be a single name, a CSV list or a * pattern. If requested is
None, allowed is used directly (pattern/CSV expansion is left to the driver). If
requested is given, every CSV element of it must match at least one allowed pattern,
otherwise the request is rejected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requested
|
str | None
|
The index/indices requested by the agent, or |
required |
allowed
|
str
|
The configured allowed index pattern/CSV. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The index/indices to actually query. |
Raises:
| Type | Description |
|---|---|
QueryNotAllowedError
|
If a requested index does not match any allowed pattern. |
Source code in src/deep_db_agents/dialects/search_base.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |