langchain-vericto 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. langchain_vericto-0.1.0/.gitignore +12 -0
  2. langchain_vericto-0.1.0/CHANGELOG.md +36 -0
  3. langchain_vericto-0.1.0/LICENSE +202 -0
  4. langchain_vericto-0.1.0/NOTICE +2 -0
  5. langchain_vericto-0.1.0/PKG-INFO +297 -0
  6. langchain_vericto-0.1.0/README.md +262 -0
  7. langchain_vericto-0.1.0/SECURITY.md +62 -0
  8. langchain_vericto-0.1.0/TRADEMARKS.md +39 -0
  9. langchain_vericto-0.1.0/examples/quickstart.py +79 -0
  10. langchain_vericto-0.1.0/langchain_vericto/__init__.py +48 -0
  11. langchain_vericto-0.1.0/langchain_vericto/_guard.py +52 -0
  12. langchain_vericto-0.1.0/langchain_vericto/_verdict.py +169 -0
  13. langchain_vericto-0.1.0/langchain_vericto/_version.py +6 -0
  14. langchain_vericto-0.1.0/langchain_vericto/py.typed +0 -0
  15. langchain_vericto-0.1.0/langchain_vericto/sql_database.py +130 -0
  16. langchain_vericto-0.1.0/langchain_vericto/tools.py +226 -0
  17. langchain_vericto-0.1.0/pyproject.toml +172 -0
  18. langchain_vericto-0.1.0/tests/__init__.py +0 -0
  19. langchain_vericto-0.1.0/tests/integration_tests/__init__.py +0 -0
  20. langchain_vericto-0.1.0/tests/integration_tests/conftest.py +52 -0
  21. langchain_vericto-0.1.0/tests/integration_tests/test_compile.py +11 -0
  22. langchain_vericto-0.1.0/tests/integration_tests/test_offline.py +127 -0
  23. langchain_vericto-0.1.0/tests/integration_tests/test_online.py +48 -0
  24. langchain_vericto-0.1.0/tests/unit_tests/__init__.py +0 -0
  25. langchain_vericto-0.1.0/tests/unit_tests/conftest.py +22 -0
  26. langchain_vericto-0.1.0/tests/unit_tests/fakes.py +94 -0
  27. langchain_vericto-0.1.0/tests/unit_tests/test_agent.py +103 -0
  28. langchain_vericto-0.1.0/tests/unit_tests/test_imports.py +30 -0
  29. langchain_vericto-0.1.0/tests/unit_tests/test_sql_database.py +168 -0
  30. langchain_vericto-0.1.0/tests/unit_tests/test_standard.py +35 -0
  31. langchain_vericto-0.1.0/tests/unit_tests/test_tools.py +221 -0
@@ -0,0 +1,12 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ .mypy_cache/
5
+ .ruff_cache/
6
+ .pytest_cache/
7
+ .coverage
8
+ htmlcov/
9
+ build/
10
+ dist/
11
+ *.egg-info/
12
+ .DS_Store
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ All notable changes to this package are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2026-11-15
10
+
11
+ First release.
12
+
13
+ ### Added
14
+
15
+ - `VerictoSQLCheck`, a LangChain tool (`BaseTool`, typed `args_schema`, sync and
16
+ async) that checks a SQL statement with Vericto without running it and returns
17
+ a structured verdict as JSON: `decision`, `allowed`, `blocked`, `rule_codes`,
18
+ `messages`, `suggested_fix`, `findings`, `rewritten_query`, provenance (`mode`,
19
+ `engine_version`, `ruleset_version`, `event_id`) and a `summary` for the model.
20
+ With a `ToolCall`, the `ToolMessage` carries the verdict dict as its
21
+ `artifact`. `VerictoSQLCheck.from_database(db)` shares a database's guard and
22
+ dialect.
23
+ - `VerictoSQLDatabase` (extra `sql`), a `langchain_community` `SQLDatabase` that
24
+ checks every statement before it runs (`run`, `run_no_throw`,
25
+ `SQLDatabaseToolkit`, `QuerySQLDatabaseTool`) in the engine's dialect, and
26
+ refuses blocked ones with a message naming the rule and the suggested fix
27
+ (`on_block="return"`, default) or `vericto.VerictoBlocked` (`"raise"`). Built on
28
+ the Vericto SDK's `vericto.langchain` integration.
29
+ - Offline mode (`offline=True` or `VERICTO_OFFLINE=1`): the standard rules of the
30
+ local engine in the Vericto CLI 2.1.0+, no account, no network. Online mode
31
+ (`VERICTO_API_KEY`, `VERICTO_DATABASE_ID`): your workspace's rules through the
32
+ Vericto Runtime API.
33
+ - `fail_mode="closed"` by default for both classes; `"open"` and `None`
34
+ (`VERICTO_FAIL_MODE`) are opt-in.
35
+ - LangChain standard tests (`langchain-tests` 1.1.9): `ToolsUnitTests` and,
36
+ offline against the real engine, `ToolsIntegrationTests`.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ langchain-vericto (the Vericto integration for LangChain)
2
+ Copyright 2026 Vericto S.A.S.
@@ -0,0 +1,297 @@
1
+ Metadata-Version: 2.5
2
+ Name: langchain-vericto
3
+ Version: 0.1.0
4
+ Summary: An integration package connecting Vericto (database guardrails for AI agents) and LangChain: check every SQL statement against Vericto's rules before it runs.
5
+ Project-URL: Homepage, https://vericto.com
6
+ Project-URL: Documentation, https://github.com/vericto/langchain-vericto#readme
7
+ Project-URL: Repository, https://github.com/vericto/langchain-vericto
8
+ Project-URL: Issues, https://github.com/vericto/langchain-vericto/issues
9
+ Project-URL: Changelog, https://github.com/vericto/langchain-vericto/blob/main/CHANGELOG.md
10
+ Author-email: Vericto <security@vericto.com>
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ License-File: NOTICE
14
+ Keywords: ai-agents,database-guardrails,guardrails,langchain,sql,sql-agent,text-to-sql,vericto
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Topic :: Database
25
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
26
+ Classifier: Topic :: Security
27
+ Classifier: Typing :: Typed
28
+ Requires-Python: <4.0.0,>=3.11.0
29
+ Requires-Dist: langchain-core<2.0.0,>=1.7.1
30
+ Requires-Dist: vericto<0.9.0,>=0.8.0
31
+ Provides-Extra: sql
32
+ Requires-Dist: langchain-community<0.5,>=0.3; extra == 'sql'
33
+ Requires-Dist: sqlalchemy<3,>=1.4; extra == 'sql'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # langchain-vericto
37
+
38
+ [![PyPI](https://img.shields.io/pypi/v/langchain-vericto?label=PyPI)](https://pypi.org/project/langchain-vericto/)
39
+ [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
40
+
41
+ The LangChain integration for [Vericto](https://vericto.com), database guardrails
42
+ for AI agents. Vericto parses each SQL statement into an AST and checks it
43
+ against deterministic rules before it runs: `DELETE` or `UPDATE` without
44
+ `WHERE`, `DROP TABLE`, unbounded `SELECT`, and more. No LLM is involved in the
45
+ decision; the same SQL always gets the same verdict.
46
+
47
+ This package gives a LangChain agent two things:
48
+
49
+ - **`VerictoSQLCheck`**: a tool that checks a statement and returns a structured
50
+ verdict (allowed or blocked, rule codes, messages, suggested fix) without
51
+ running it. Sync and async.
52
+ - **`VerictoSQLDatabase`**: a drop-in `SQLDatabase` (for `SQLDatabaseToolkit`,
53
+ `QuerySQLDatabaseTool`, `create_sql_agent` and query chains) that checks every
54
+ statement before it reaches the database and refuses blocked ones with a
55
+ message the agent can act on. Fail-closed by default.
56
+
57
+ Two ways to evaluate, same API:
58
+
59
+ | | Offline | Online |
60
+ |---|---|---|
61
+ | Account, network | none; the SQL never leaves the machine | a Vericto workspace; the SQL goes to the Vericto Runtime API |
62
+ | Needs | the Vericto CLI 2.1.0 or later installed | `VERICTO_API_KEY` (scope `proxy:evaluate`) and `VERICTO_DATABASE_ID` |
63
+ | Rules | the standard rules of the engine in the CLI, at their default severities | your workspace's rules: overrides, custom rules |
64
+ | Sensitive-column masking, agent allowlists, business policies, audit trail | no | yes |
65
+ | Metered | no | counts against the workspace's monthly query quota |
66
+
67
+ ## Installation
68
+
69
+ ```bash
70
+ pip install -U langchain-vericto # the check tool
71
+ pip install -U "langchain-vericto[sql]" # plus VerictoSQLDatabase (langchain-community, SQLAlchemy)
72
+ ```
73
+
74
+ Python 3.11 or later.
75
+
76
+ ## Quickstart: offline, no account
77
+
78
+ Install the Vericto CLI (it carries the engine; nothing is downloaded at run
79
+ time):
80
+
81
+ ```bash
82
+ npm i -g @vericto/vericto-cli # or: brew install vericto/tap/vericto
83
+ vericto --version # 2.1.0 or later
84
+ ```
85
+
86
+ Check a statement:
87
+
88
+ ```python
89
+ import json
90
+
91
+ from langchain_vericto import VerictoSQLCheck
92
+
93
+ tool = VerictoSQLCheck(offline=True, dialect="postgres")
94
+
95
+ verdict = json.loads(tool.invoke({"query": "DELETE FROM users"}))
96
+ verdict["decision"] # 'BLOCKED'
97
+ verdict["rule_codes"] # ['VERICTO-001']
98
+ verdict["suggested_fix"] # 'DELETE FROM users WHERE id = $1'
99
+
100
+ json.loads(tool.invoke({"query": "SELECT id FROM users WHERE id = 42 LIMIT 1"}))["decision"]
101
+ # 'ALLOWED'
102
+ ```
103
+
104
+ Guard a database (here SQLite; any SQLAlchemy URL works):
105
+
106
+ ```python
107
+ from langchain_vericto import VerictoSQLDatabase
108
+
109
+ db = VerictoSQLDatabase.from_uri("sqlite:///shop.db", offline=True)
110
+
111
+ db.run("SELECT id, total FROM orders WHERE id = 1 LIMIT 10") # runs
112
+ db.run("DELETE FROM orders")
113
+ # Error: Vericto blocked this query (VERICTO-001, severity critical). It was NOT executed.
114
+ # Suggested fix: DELETE FROM orders WHERE id = $1
115
+ # Rewrite the query following the suggested fix and try again.
116
+ ```
117
+
118
+ The dialect comes from the engine (`sqlite` here). `examples/quickstart.py` runs
119
+ all of this end to end.
120
+
121
+ ## Quickstart: online, your workspace's rules
122
+
123
+ Create an API key with the `proxy:evaluate` scope in the Vericto dashboard and
124
+ register the database you are protecting. Then:
125
+
126
+ ```bash
127
+ export VERICTO_API_KEY="vtro_..."
128
+ export VERICTO_DATABASE_ID="..." # the registered database's id
129
+ ```
130
+
131
+ ```python
132
+ from langchain_vericto import VerictoSQLCheck, VerictoSQLDatabase
133
+
134
+ tool = VerictoSQLCheck(dialect="postgres")
135
+ db = VerictoSQLDatabase.from_uri("postgresql+psycopg://...")
136
+ ```
137
+
138
+ The verdicts now follow your workspace's rules, sensitive columns come back
139
+ masked (`rewritten_query`, and the database runs the rewrite), and every
140
+ evaluation has an `event_id` in the audit trail.
141
+
142
+ Offline mode is never chosen on its own: with no `offline=True`, no
143
+ `VERICTO_OFFLINE=1` and no API key, the first check raises
144
+ `vericto.VerictoConfigError`. Offline mode combined with an API key raises too
145
+ ("choose one"), so a missing secret can never quietly fall back to fewer rules.
146
+
147
+ ## Use it in an agent
148
+
149
+ ```python
150
+ # pip install "langchain-vericto[sql]" "langchain[anthropic]"
151
+ from langchain.agents import create_agent
152
+ from langchain.chat_models import init_chat_model
153
+ from langchain_community.agent_toolkits import SQLDatabaseToolkit
154
+
155
+ from langchain_vericto import VerictoSQLCheck, VerictoSQLDatabase
156
+
157
+ db = VerictoSQLDatabase.from_uri("sqlite:///shop.db", offline=True)
158
+ model = init_chat_model("claude-sonnet-4-6") # any chat model with tool calling
159
+
160
+ toolkit = SQLDatabaseToolkit(db=db, llm=model)
161
+ agent = create_agent(
162
+ model=model,
163
+ tools=[*toolkit.get_tools(), VerictoSQLCheck.from_database(db)],
164
+ system_prompt=(
165
+ "You answer questions about the shop database. Check every query with "
166
+ "vericto_sql_check before running it, and never run a blocked query."
167
+ ),
168
+ )
169
+ agent.invoke({"messages": [{"role": "user", "content": "Delete all orders."}]})
170
+ ```
171
+
172
+ Every query the toolkit runs goes through Vericto, whether or not the model
173
+ calls the check tool first: the check tool lets it ask before it tries, the
174
+ database refuses what is blocked either way.
175
+
176
+ ## The verdict
177
+
178
+ `VerictoSQLCheck` returns the verdict as a JSON string; called with a
179
+ `ToolCall`, the `ToolMessage` carries the same dict as its `artifact`.
180
+ `tool.check(query)` returns the SDK's `vericto.Verdict`, and
181
+ `langchain_vericto.verdict_to_dict` turns it into the dict.
182
+
183
+ | Key | Meaning |
184
+ |---|---|
185
+ | `decision` | `ALLOWED`, `FLAGGED`, `MONITORED`, `PARSE_ERROR`, `BLOCKED`, or `UNEVALUATED` (no verdict, `fail_mode="open"`) |
186
+ | `allowed` | Vericto lets it run: `ALLOWED`, `FLAGGED`, `MONITORED`, `PARSE_ERROR`. Never for `BLOCKED` or `UNEVALUATED`. |
187
+ | `blocked`, `evaluated` | booleans |
188
+ | `rule_codes` | rules that matched, deciding rule first (`["VERICTO-001"]`) |
189
+ | `severity` | the deciding rule's severity |
190
+ | `messages` | readable reasons (server message, each finding and where it matched) |
191
+ | `suggested_fix` | a safer statement or advice, when Vericto has one |
192
+ | `findings` | `rule_code`, `severity`, `suggested_fix`, `location` (AST path) per rule |
193
+ | `rewritten_query` | the statement that runs instead, sensitive columns masked (online) |
194
+ | `dialect`, `mode`, `engine_version`, `ruleset_version`, `event_id` | provenance: `mode` is `offline` or `online`; `event_id` online only |
195
+ | `summary` | one paragraph for the model: what happened and what to do next |
196
+
197
+ A text with several statements gets one verdict, the strongest finding among
198
+ them: `SELECT 1; DELETE FROM orders` is `BLOCKED` by `VERICTO-001`.
199
+
200
+ ## Fail mode
201
+
202
+ When Vericto cannot answer (network, timeout, quota, the local engine process
203
+ failing):
204
+
205
+ - `fail_mode="closed"` (default): `vericto.VerictoUnavailable` is raised and
206
+ nothing runs. It is never turned into text for the model.
207
+ - `fail_mode="open"`: `VerictoSQLDatabase` runs the statement unevaluated with a
208
+ `vericto.VerictoFailOpenWarning`; `VerictoSQLCheck` returns an `UNEVALUATED`
209
+ verdict with `allowed: false`.
210
+ - `fail_mode=None`: read `VERICTO_FAIL_MODE` (closed when unset).
211
+
212
+ Configuration errors (bad key, missing scope, no CLI in offline mode, an
213
+ unsupported dialect) raise `vericto.VerictoConfigError` in both modes.
214
+
215
+ ## Configuration
216
+
217
+ Both classes take the same connection arguments; each falls back to an
218
+ environment variable.
219
+
220
+ | Argument | Environment | Default |
221
+ |---|---|---|
222
+ | `offline` | `VERICTO_OFFLINE` | online |
223
+ | `api_key` | `VERICTO_API_KEY` | required online |
224
+ | `database_id` | `VERICTO_DATABASE_ID` | required online |
225
+ | `api_url` | `VERICTO_API_URL` | `https://api.vericto.com` |
226
+ | `fail_mode` | `VERICTO_FAIL_MODE` (only with `fail_mode=None`) | `"closed"` |
227
+ | `timeout` | `VERICTO_TIMEOUT` (online) | 5 s online, 30 s offline |
228
+ | `offline_cli_path` | `VERICTO_CLI` | `vericto` on `PATH` |
229
+ | `guard` | | a `vericto.Vericto` to share instead |
230
+
231
+ `VerictoSQLCheck` also takes `dialect` (default `postgres`; the model may pass
232
+ another one per call). `VerictoSQLDatabase` takes every `SQLDatabase` argument,
233
+ `dialect` (default: the engine's), `on_block` (`"return"`, default, or `"raise"`
234
+ to raise `vericto.VerictoBlocked`), and `context` / `end_user` for business
235
+ policies (see the [Vericto SDK](https://github.com/vericto/vericto-python#readme)).
236
+
237
+ Call `close()` on either object when you are done: it stops the local
238
+ `vericto serve` process (offline) or closes the HTTP pool (online). A guard
239
+ passed with `guard=` is left to its owner.
240
+
241
+ ## How it works, and its limits
242
+
243
+ The evaluation is done by the official Vericto SDK for Python
244
+ ([`vericto`](https://pypi.org/project/vericto/), Apache-2.0), which this package
245
+ depends on; `VerictoSQLDatabase` is built on the SDK's `vericto.langchain`
246
+ integration.
247
+
248
+ - **Online**, the SDK sends the statement (never parameter values) to the
249
+ Vericto Runtime API (`POST /api/v1/proxy/query`, header `X-API-Key`, scope
250
+ `proxy:evaluate`) over HTTPS, with retries and backoff.
251
+ - **Offline**, the SDK starts the installed Vericto CLI once as
252
+ `vericto serve --stdio` and sends it JSON Lines over a pipe. The engine runs
253
+ in that separate process (it is AGPL-3.0-only and is never imported, linked or
254
+ bundled by this package). No network listener, no request to anyone.
255
+
256
+ Limits, stated plainly:
257
+
258
+ - Offline mode needs the CLI installed and checks the standard rules only: no
259
+ custom rules or severity overrides, no masking, no agent allowlists, no
260
+ business policies, no audit trail. It answers "is this SQL obviously
261
+ dangerous?", not "is this allowed by my organization's policy?".
262
+ - Vericto checks the statement, not the data: it does not know how many rows a
263
+ `WHERE` matches, and it does not replace database permissions. Give the agent
264
+ a database role with the least privilege it needs as well.
265
+ - A statement Vericto cannot parse is `PARSE_ERROR`: offline (and by default
266
+ online) it is allowed to run and reported, per policy.
267
+ - The SDK is synchronous; the async paths run it in a worker thread.
268
+ - `VerictoSQLDatabase` subclasses `langchain_community`'s `SQLDatabase`.
269
+ [`langchain-community` is being sunset](https://github.com/langchain-ai/langchain-community/issues/674):
270
+ it still installs and works (0.4.x), and it is only needed for the `sql`
271
+ extra. `VerictoSQLCheck` depends on `langchain-core` alone. For SQLAlchemy code
272
+ without `SQLDatabase`, `vericto.sqlalchemy.instrument(engine)` from the SDK
273
+ guards an engine directly.
274
+ - Suggested fixes come from the engine and may use placeholders (`$1`) that you
275
+ fill in; they are advice, not SQL to run blindly.
276
+
277
+ ## Development
278
+
279
+ ```bash
280
+ uv sync # Python 3.11+, uv
281
+ make lint # ruff check, ruff format --check, mypy
282
+ make test # unit tests, LangChain standard tests, no network
283
+ make integration_test # against the real engine (see below)
284
+ uv build && uvx twine check --strict dist/*
285
+ ```
286
+
287
+ Integration tests run offline against the real engine when a Vericto CLI is on
288
+ `PATH` or in `VERICTO_CLI` (`VERICTO_REQUIRE_CLI=1` makes a missing CLI a
289
+ failure instead of a skip), and online when `VERICTO_API_KEY` and
290
+ `VERICTO_DATABASE_ID` are set. See [CONTRIBUTING.md](CONTRIBUTING.md).
291
+
292
+ ## License
293
+
294
+ [Apache License 2.0](LICENSE). See [NOTICE](NOTICE) and
295
+ [TRADEMARKS.md](TRADEMARKS.md). The Vericto engine and CLI are separate programs
296
+ under their own license (AGPL-3.0-only); this package talks to the CLI as a
297
+ separate process and does not include it.