LlamaIndex.
Check every SQL statement a LlamaIndex agent or text-to-SQL engine writes before it reaches the database: tools for the agent and a guarded SQLDatabase, offline or online.
Available. llama-index-tools-vericto 0.1.0 on PyPI (Apache-2.0), for Python 3.11 or later and llama-index-core 0.13 or later. The evaluation is done by the Python SDK (vericto, Apache-2.0), which already ships the vericto.llamaindex module; this package adds the agent tools and the guarded SQLDatabase.
Overview
Vericto checks every SQL statement LlamaIndex writes before it reaches the database: it parses it into a syntax tree and evaluates it against deterministic rules (for example VERICTO-001, a DELETE without WHERE). No model takes part in the decision: the same SQL always gets the same verdict. A blocked statement is not executed, and the model gets the rule and the suggested fix to try again.
- Tools for the agent:
VerictoToolSpecis aBaseToolSpec.check_sqlreturns the verdict and runs nothing; given a guarded database it also addsrun_sql,list_tablesanddescribe_tables. Each one has an async version. - A guarded database:
VerictoSQLDatabaseis a drop-in LlamaIndexSQLDatabase, so it works as it is inNLSQLTableQueryEngine,SQLTableRetrieverQueryEngineandNLSQLRetriever. - Six dialects: PostgreSQL, MySQL, Oracle, SQL Server, Snowflake and SQLite.
Offline or online
Offline: the local engine of the Vericto CLI 2.1.0 or later, with no account and no network; the SQL never leaves the machine. Turn it on with offline=True or VERICTO_OFFLINE=1. It checks the 42 standard rules at their default severities: a DROP TABLE is blocked.
Online: your workspace's rules through the Runtime API, with sensitive columns masked, agent allowlists, business policies and an audit trail. It needs VERICTO_API_KEY (scope proxy:evaluate) and VERICTO_DATABASE_ID, the database registered in the dashboard. When a column is masked, the verdict carries the rewritten statement and the database runs that one.
Offline mode is never chosen on its own: with no offline=True, no VERICTO_OFFLINE=1 and no API key, the first check raises vericto.VerictoConfigError. Offline mode combined with an API key raises too ("choose one"), so a missing secret cannot quietly downgrade the check to fewer rules.
Install
The package brings the Python SDK as a dependency. The engine comes in the CLI, which runs as a separate process: offline mode needs it installed and downloads nothing at run time.
pip install -U llama-index-tools-vericto # or: uv add llama-index-tools-vericto
# Offline mode: the Vericto CLI, 2.1.0 or later (it carries the engine)
npm i -g @vericto/vericto-cli # or: brew install vericto/tap/vericto
export VERICTO_OFFLINE=1 # or offline=True in code
# Online mode: your workspace
export VERICTO_API_KEY=vtro_... # scope proxy:evaluate
export VERICTO_DATABASE_ID=<database-id> # the database in the dashboard
The agent's tools: VerictoToolSpec
to_tool_list() returns the tools ready for any LlamaIndex agent. With no database it brings only check_sql, which takes query — the exact SQL — and an optional dialect, and returns the verdict as JSON: decision, allowed, blocked, rule_codes, messages, suggested_fix, findings and a summary the model can act on. It runs nothing.
import json
from llama_index.tools.vericto import VerictoToolSpec
spec = VerictoToolSpec(offline=True, dialect="postgres")
verdict = json.loads(spec.check_sql("DELETE FROM users"))
print(verdict["decision"], verdict["rule_codes"], verdict["suggested_fix"])
print(verdict["summary"])
print([t.metadata.name for t in spec.to_tool_list()])
BLOCKED ['VERICTO-001'] DELETE FROM users WHERE id = $1
Vericto blocked this query (VERICTO-001, severity critical). It was NOT executed. Suggested fix: DELETE FROM users WHERE id = $1 Rewrite the query following the suggested fix and try again.
['check_sql']
Built with a guarded database, the spec shares its guard and its dialect and adds three more tools: run_sql, which runs through that database, and list_tables and describe_tables, which read the schema and are not sent to Vericto. A blocked statement never reaches the database: run_sql returns the reason and the fix instead of the rows.
The spec refuses to work without its guarantees. A plain SQLDatabase raises TypeError, because its statements would not go through Vericto, and passing the connection arguments to both objects raises ValueError: they go to VerictoSQLDatabase only.
from llama_index.core import SQLDatabase
from llama_index.tools.vericto import VerictoSQLDatabase, VerictoToolSpec
db = VerictoSQLDatabase.from_uri("sqlite:///shop.db", offline=True)
spec = VerictoToolSpec(db) # shares the database's guard and dialect
print([t.metadata.name for t in spec.to_tool_list()])
print(spec.list_tables())
VerictoToolSpec(SQLDatabase.from_uri("sqlite:///shop.db")) # TypeError
VerictoToolSpec(db, offline=True) # ValueError
['check_sql', 'run_sql', 'list_tables', 'describe_tables']
['orders']
TypeError: sql_database must be a llama_index.tools.vericto.VerictoSQLDatabase: a plain SQLDatabase would run statements Vericto never checked
ValueError: offline: pass the Vericto connection arguments to VerictoSQLDatabase; the tool spec shares its guard
Each tool carries a description and an input schema written for the model. To change them, pass func_to_metadata_mapping to to_tool_list(). check_sql and run_sql also have async versions (acheck_sql and arun_sql), which run the synchronous SDK in a worker thread.
Guard a database: VerictoSQLDatabase
It takes every SQLDatabase argument (include_tables, sample_rows_in_table_info…) and checks every statement run_sql and insert_into_table send, in the SQLAlchemy engine's dialect. A blocked statement is not executed: run_sql returns the explanation as the result and the detail in metadata["vericto_blocked"]. With on_block="raise" it raises vericto.VerictoBlocked.
from llama_index.tools.vericto import VerictoSQLDatabase
db = VerictoSQLDatabase.from_uri("sqlite:///shop.db", offline=True)
print(db.run_sql("SELECT id, total FROM orders WHERE id = 1 LIMIT 10")[0])
result, metadata = db.run_sql("DELETE FROM orders")
print(result)
print(metadata["vericto_blocked"])
print(db.run_sql("SELECT count(*) FROM orders LIMIT 1")[0]) # nothing was deleted
[(1, 10)]
Error: Vericto blocked this query (VERICTO-001, severity critical). It was NOT executed.
Suggested fix: DELETE FROM orders WHERE id = $1
Rewrite the query following the suggested fix and try again.
{'rule_code': 'VERICTO-001', 'severity': 'critical', 'suggested_fix': 'DELETE FROM orders WHERE id = $1', 'event_id': None}
[(2,)]
Call close() when you are done: it stops the local CLI process (offline) or closes the HTTP pool (online). A guard you passed with guard=, or that the spec shares with the database, is left to its owner.
Real output: llama-index-tools-vericto 0.1.0 with vericto 0.9.0 and CLI 2.2.0 in offline mode (engine 5.0.0), with llama-index-core 0.14.26, on Python 3.13 and macOS on 21 November 2026. The SDK also logs every non-ALLOWED verdict to stderr, for example vericto: statement BLOCKED rule=VERICTO-001 severity=critical event_id=-. Online, the rules, the severities and the fixes are your workspace's, and event_id points into the audit trail.
Text-to-SQL engines
Because it is a SQLDatabase, it drops into LlamaIndex's text-to-SQL engines unchanged: the SQL the model generates goes through Vericto before it runs. When it is blocked, nothing runs: the synthesis step reads Vericto's explanation instead of a result, so the answer says why, and response.metadata["vericto_blocked"] carries the rule, the severity, the suggested fix and the event id.
from llama_index.core.query_engine import NLSQLTableQueryEngine
from llama_index.tools.vericto import VerictoSQLDatabase
db = VerictoSQLDatabase.from_uri("sqlite:///shop.db", offline=True, include_tables=["orders"])
query_engine = NLSQLTableQueryEngine(sql_database=db, tables=["orders"], llm=llm)
response = query_engine.query("Delete all orders")
print(response.metadata["vericto_blocked"])
The same holds for SQLTableRetrieverQueryEngine, NLSQLRetriever and any other code that runs through run_sql. This example needs a model and its API key, so it was not run here; the outputs in the sections above were.
In an agent
The spec's tools go straight into a FunctionAgent, or any LlamaIndex agent that calls functions. This example also needs a model with tool calling and its API key.
# pip install llama-index-tools-vericto llama-index-llms-anthropic
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.anthropic import Anthropic
from llama_index.tools.vericto import VerictoSQLDatabase, VerictoToolSpec
db = VerictoSQLDatabase.from_uri("sqlite:///shop.db", offline=True)
agent = FunctionAgent(
tools=VerictoToolSpec(db).to_tool_list(), # check_sql, run_sql, list_tables, describe_tables
llm=Anthropic(model="claude-sonnet-5-5"), # any function-calling LLM
system_prompt=(
"You answer questions about the shop database. Check every query with "
"check_sql before running it, and never run a blocked query."
),
)
response = await agent.run("Delete all orders.")
Every statement run_sql sends goes through Vericto, whether or not the model calls check_sql first: the check tool lets it ask before it tries, and the database refuses what is blocked either way. That is why the prompt is a help, not the control: the control is in the database.
The verdict
check_sql returns the verdict as JSON (the tool output's content and raw_output). spec.check(query) returns the SDK's vericto.Verdict, and verdict_to_dict turns it into the dict.
| Key | What it means |
|---|---|
decision | ALLOWED, FLAGGED, MONITORED, PARSE_ERROR, BLOCKED or UNEVALUATED (no verdict, with fail_mode="open"). |
allowed | Vericto lets it run: ALLOWED, FLAGGED, MONITORED and PARSE_ERROR. Never for BLOCKED or UNEVALUATED. |
blocked, evaluated | Booleans. |
rule_codes, severity | The rules that matched, the deciding one first, and that one's severity. |
messages, summary | The readable reasons, and one paragraph for the model: what happened and what to do. |
suggested_fix, findings | The fix, when Vericto has one, and per rule the rule_code, the severity, its fix and the location (the path in the syntax tree). |
rewritten_query | The statement that runs instead, with sensitive columns masked (online). |
dialect, mode, engine_version, ruleset_version, event_id | Provenance: mode is offline or online, and event_id exists online only. |
print(json.loads(spec.check_sql("DELETE FROM users"))["findings"])
[{'rule_code': 'VERICTO-001', 'severity': 'critical', 'suggested_fix': 'DELETE FROM users WHERE id = $1', 'location': 'DeleteStmt > WhereClause = NULL'}]
A text with several statements gets one verdict, the strongest finding among them: SELECT 1; DELETE FROM orders is BLOCKED by VERICTO-001.
Fail closed
When Vericto cannot answer (the CLI is missing, the API does not respond, the quota ran out, the local process fails), the default mode is closed: fail_mode="closed" raises vericto.VerictoUnavailable and nothing runs. Inside a LlamaIndex agent, the exception reaches the model as a tool error.
With fail_mode="open", VerictoSQLDatabase runs the statement unevaluated and warns with vericto.VerictoFailOpenWarning, and check_sql returns an UNEVALUATED verdict with allowed: false. With fail_mode=None it reads VERICTO_FAIL_MODE (closed when unset). Configuration errors — a bad key, a missing scope, no CLI in offline mode, an unsupported dialect — raise vericto.VerictoConfigError in both modes. See Fail closed and retries.
Limits
- Offline checks the 42 standard rules only: no custom rules or severity overrides, no masking, no agent allowlists, no business policies and no audit trail. It answers "is this SQL obviously dangerous?", not "is this allowed by my organization's policy?".
- The checkpoint is the guarded database. Only what goes through
run_sqlandinsert_into_tableis checked. Code that uses the SQLAlchemy engine directly does not go through Vericto, and that is the case forDatabaseToolSpecfromllama-index-tools-database: its tools are not guarded. UseVerictoToolSpec(db)instead, or guard the engine itself with the SDK'svericto.sqlalchemy.instrument(engine). Another connection to the same database does not go through Vericto either; that is what the TCP proxy is for. - Vericto checks the statement, not the data: it does not know how many rows a
WHEREmatches and it does not replace database permissions. Give the agent a database role with the least privilege it needs as well. - A statement Vericto cannot parse ends up as
PARSE_ERROR: offline, and online by default, it is allowed to run and reported, per the workspace policy. - The SDK is synchronous and the async tools run it in a worker thread.
NLSQLTableQueryEngine.aquerycallsrun_sqlfrom the event loop, so there each check blocks the loop for one round trip. - Suggested fixes come from the engine and may carry placeholders (
$1) that you fill in: they are advice, not SQL to run blindly. - This package is for LlamaIndex in Python. LlamaIndex.TS has no integration yet.