guardtrellis 0.1.0a1__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 (35) hide show
  1. guardtrellis-0.1.0a1/.gitignore +13 -0
  2. guardtrellis-0.1.0a1/CHANGELOG.md +39 -0
  3. guardtrellis-0.1.0a1/CONTRIBUTING.md +93 -0
  4. guardtrellis-0.1.0a1/LICENSE +202 -0
  5. guardtrellis-0.1.0a1/PKG-INFO +165 -0
  6. guardtrellis-0.1.0a1/README.md +134 -0
  7. guardtrellis-0.1.0a1/ROADMAP.md +102 -0
  8. guardtrellis-0.1.0a1/docs/api.md +123 -0
  9. guardtrellis-0.1.0a1/docs/limitations.md +78 -0
  10. guardtrellis-0.1.0a1/docs/releasing.md +158 -0
  11. guardtrellis-0.1.0a1/evaluation/README.md +44 -0
  12. guardtrellis-0.1.0a1/evaluation/REPORT.md +40 -0
  13. guardtrellis-0.1.0a1/evaluation/corpus.jsonl +72 -0
  14. guardtrellis-0.1.0a1/evaluation/results.json +8053 -0
  15. guardtrellis-0.1.0a1/evaluation/run.py +226 -0
  16. guardtrellis-0.1.0a1/examples/__init__.py +1 -0
  17. guardtrellis-0.1.0a1/examples/fastapi_app.py +56 -0
  18. guardtrellis-0.1.0a1/examples/langgraph_app.py +48 -0
  19. guardtrellis-0.1.0a1/examples/plain_callable.py +34 -0
  20. guardtrellis-0.1.0a1/pyproject.toml +64 -0
  21. guardtrellis-0.1.0a1/scripts/release_artifacts.py +239 -0
  22. guardtrellis-0.1.0a1/scripts/smoke_dist.py +93 -0
  23. guardtrellis-0.1.0a1/src/guardtrellis/__init__.py +31 -0
  24. guardtrellis-0.1.0a1/src/guardtrellis/guard.py +276 -0
  25. guardtrellis-0.1.0a1/src/guardtrellis/json_check.py +170 -0
  26. guardtrellis-0.1.0a1/src/guardtrellis/models.py +149 -0
  27. guardtrellis-0.1.0a1/src/guardtrellis/py.typed +0 -0
  28. guardtrellis-0.1.0a1/src/guardtrellis/scanners.py +162 -0
  29. guardtrellis-0.1.0a1/src/guardtrellis/tools.py +87 -0
  30. guardtrellis-0.1.0a1/tests/test_examples.py +60 -0
  31. guardtrellis-0.1.0a1/tests/test_guard.py +334 -0
  32. guardtrellis-0.1.0a1/tests/test_json_tools.py +247 -0
  33. guardtrellis-0.1.0a1/tests/test_release_artifacts.py +173 -0
  34. guardtrellis-0.1.0a1/tests/test_scanners.py +156 -0
  35. guardtrellis-0.1.0a1/uv.lock +2013 -0
@@ -0,0 +1,13 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ dist/
8
+ build/
9
+ *.egg-info/
10
+ .DS_Store
11
+ .env
12
+ .env.*
13
+ handoff.md
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0a1 — release candidate
4
+
5
+ The first alpha is prepared from source. Publication and its verification are tracked in
6
+ [#4](https://github.com/sahilmathur254/guardtrellis/issues/4); this entry does not claim an upload.
7
+
8
+ ### Included
9
+
10
+ - Typed `Guard` and scanner contracts with synchronous/asynchronous entry points,
11
+ explicit input/output/retrieval/tool stages, and ordered redaction provenance.
12
+ - Explicit allow, warn, redact, block, and error outcomes. Rejected inputs do not reach
13
+ callbacks; blocked/error results do not expose ordinary deliverable text or arguments.
14
+ - Local checks for documented PII shapes, selected secret signatures, Unicode control/format
15
+ characters, literal policies, strict JSON/constrained Draft 2020-12 schemas, and tool-call
16
+ name/object-argument validation.
17
+ - Bounded text, findings, and JSON depth; per-operation async waits with documented
18
+ cancellation limitations; metadata-only diagnostics and payload-free rejection errors.
19
+ - Optional, credential-free callable, FastAPI, and LangGraph examples. The core requires
20
+ only jsonschema and referencing plus their dependencies, with no provider SDK or model download.
21
+ - Python 3.11–3.14 support, typed package metadata, Apache-2.0 licensing, wheel/sdist
22
+ installation checks, and a reproducible synthetic smoke evaluation with retained failures.
23
+
24
+ ### Compatibility and known limitations
25
+
26
+ This is an experimental API. Names, contracts, and dependencies can change before a stable
27
+ version; such changes will be documented with migration guidance. Pin an exact alpha version
28
+ or source commit when evaluating it. No new runtime API changes are included in release preparation.
29
+
30
+ Checks inspect only explicitly supplied text and configured formats. Coverage excludes many
31
+ PII/secret formats and semantic safety judgments. WARN permits delivery, unconfigured stages
32
+ permit bounded text, and tool validation supplies neither authorization nor sandboxing.
33
+ Outputs are checked only after the complete callback response; there is no streaming API.
34
+ Async timeout does not terminate arbitrary Python code or undo callback side effects.
35
+
36
+ The 72-case authored smoke corpus includes four known misses and two false positives. Its
37
+ aggregate results are not a general accuracy estimate or an independent security benchmark.
38
+ See [limitations](docs/limitations.md), [API contracts](docs/api.md), and the
39
+ [evaluation report](evaluation/REPORT.md) before integrating.
@@ -0,0 +1,93 @@
1
+ # Contributing to GuardTrellis
2
+
3
+ ## Choose work
4
+
5
+ Start with the [roadmap](ROADMAP.md) and the public
6
+ [GitHub Project](https://github.com/users/sahilmathur254/projects/3). Its **Ready to contribute**
7
+ view contains scoped work that can start now. Issues labelled
8
+ [good first issue](https://github.com/sahilmathur254/guardtrellis/labels/good%20first%20issue)
9
+ have a small entry point; [help wanted](https://github.com/sahilmathur254/guardtrellis/labels/help%20wanted)
10
+ also includes more involved work.
11
+
12
+ Read the issue's acceptance criteria, dependencies, and existing discussion before starting.
13
+ Comment with your intended approach so the maintainer can coordinate overlapping work.
14
+ For a new substantial feature, open a proposal first. Documentation improvements, safe
15
+ reproductions, tests, and evaluation cases are useful contributions too.
16
+
17
+ Repository issues hold scope and completion evidence; the project holds status and priority.
18
+ Maintainers manage project status and assignments. You can contribute through a fork and
19
+ pull request without project or repository write access. No response-time commitment is made.
20
+
21
+ ## Set up a contribution
22
+
23
+ Fork the repository on GitHub, replace `YOUR_USERNAME` below with your account, then run:
24
+
25
+ ```sh
26
+ git clone https://github.com/YOUR_USERNAME/guardtrellis.git
27
+ cd guardtrellis
28
+ git remote add upstream https://github.com/sahilmathur254/guardtrellis.git
29
+ git switch -c describe-your-change
30
+ ```
31
+
32
+ Use Python 3.11–3.14. The project uses a src layout, Hatchling, and uv's dependency lock.
33
+ The runtime depends only on jsonschema and referencing plus their dependencies. Keep
34
+ model providers, frameworks, network clients, and model downloads out of core dependencies.
35
+
36
+ ```sh
37
+ uv sync --frozen --all-extras --group dev
38
+ uv run pytest
39
+ uv run ruff check .
40
+ uv run ruff format --check .
41
+ uv run mypy
42
+ uv run python evaluation/run.py
43
+ uv build
44
+ uv run python scripts/smoke_dist.py
45
+ ```
46
+
47
+ If the default uv cache is unavailable, set `UV_CACHE_DIR` to a writable local directory.
48
+ On machines whose Python trust store is incomplete, use a verified system CA bundle via
49
+ `SSL_CERT_FILE`; never disable certificate verification. uv must be installed separately.
50
+
51
+ ## Keep changes reviewable
52
+
53
+ Implement one scoped issue per pull request where practical. Follow the existing API and
54
+ dependency patterns. Add behavior-focused regression coverage when changing runtime behavior;
55
+ check links and examples for documentation changes. State which checks actually ran and any
56
+ remaining limitations. CI runs the full checks against submitted code.
57
+
58
+ Open a pull request from your fork to `main`, link the issue, explain the user-visible change,
59
+ and include validation evidence. Use `Fixes #NUMBER` when the PR completes the issue; use
60
+ `Refs #NUMBER` for partial work. Address review feedback before merge. Do not mark a roadmap
61
+ item complete until its acceptance criteria are met and its completion evidence is linked.
62
+
63
+ The current API is alpha and may change. Discuss public API or dependency changes before
64
+ implementation and include migration notes when compatibility is affected.
65
+
66
+ Test behavior and failure boundaries: rejected content must not reach callbacks or normal
67
+ results; scanner/callback failures must be explicit errors; no raw input belongs in logs,
68
+ reprs, generic exceptions, or diagnostics. Preserve meaningful offsets through redaction.
69
+ New checks need supported-format documentation, benign challenges, and bounded processing.
70
+ Do not add broad automatic injection-blocking phrases without evidence and explicit policy.
71
+
72
+ Use fabricated data in issues, examples, fixtures, and reports. Remove credentials and personal
73
+ data from logs and reproductions. Describe tooling or AI assistance when it affects attribution,
74
+ verification, or a reviewer's ability to reproduce the change; contributors remain responsible
75
+ for understanding and validating submitted code.
76
+
77
+ Tests run against the installed editable package. Optional example tests skip when extras
78
+ are absent; the CI matrix installs all extras, so those tests must run there. Distribution
79
+ smokes install the wheel and source archive in fresh temporary environments outside this
80
+ directory, verify core installs exclude frameworks, then install extras and execute all
81
+ three examples against each installed artifact. Build the sdist
82
+ and wheel after updating packaged documentation or evaluation results.
83
+
84
+ The workflow checks Python 3.11, 3.12, 3.13, and 3.14 on Linux. Check the run for the commit
85
+ under review; local success does not establish remote CI success. Synthetic evaluation limitations
86
+ and reported false positives/misses are part of the deliverable, not tests to tune away.
87
+ Do not include real credentials or personal data in tests, fixtures, or reports.
88
+
89
+ ## Releases and licensing
90
+
91
+ Package publication is maintainer work and follows the [release checklist](docs/releasing.md).
92
+ No PyPI release is available yet. A merged contribution does not itself trigger publication.
93
+ The project is Apache-2.0 licensed; preserve applicable notices when adding third-party material.
@@ -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,165 @@
1
+ Metadata-Version: 2.4
2
+ Name: guardtrellis
3
+ Version: 0.1.0a1
4
+ Summary: Composable local checks around model inputs, outputs, retrieval, and tools
5
+ Project-URL: Source, https://github.com/sahilmathur254/guardtrellis
6
+ Project-URL: Issues, https://github.com/sahilmathur254/guardtrellis/issues
7
+ Project-URL: Documentation, https://github.com/sahilmathur254/guardtrellis/blob/main/docs/api.md
8
+ Project-URL: Changelog, https://github.com/sahilmathur254/guardtrellis/blob/main/CHANGELOG.md
9
+ Project-URL: Roadmap, https://github.com/users/sahilmathur254/projects/3
10
+ Author: Sahil Mathur
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: <3.15,>=3.11
21
+ Requires-Dist: jsonschema<5,>=4.23
22
+ Requires-Dist: referencing<0.38,>=0.35
23
+ Provides-Extra: fastapi
24
+ Requires-Dist: fastapi<1,>=0.115; extra == 'fastapi'
25
+ Requires-Dist: httpx<1,>=0.27; extra == 'fastapi'
26
+ Requires-Dist: uvicorn<1,>=0.30; extra == 'fastapi'
27
+ Provides-Extra: langgraph
28
+ Requires-Dist: langgraph<2,>=1; extra == 'langgraph'
29
+ Requires-Dist: langsmith<1,>=0.3; extra == 'langgraph'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # GuardTrellis
33
+
34
+ A small Python SDK for local checks around model inputs, complete outputs, retrieved text,
35
+ and proposed tool calls. Policies are explicit, composable, and independent of model providers.
36
+
37
+ **Alpha: 0.1.0a1.** APIs may change before a stable release.
38
+ Supported Python: 3.11–3.14. Apache-2.0 licensed. Verified package availability is tracked
39
+ in the [first alpha release issue](https://github.com/sahilmathur254/guardtrellis/issues/4).
40
+
41
+ Use an activated virtual environment, then clone and install the source:
42
+
43
+ ```sh
44
+ git clone https://github.com/sahilmathur254/guardtrellis.git
45
+ cd guardtrellis
46
+ python -m pip install -e .
47
+ python examples/plain_callable.py
48
+ ```
49
+
50
+ ```python
51
+ from guardtrellis import Guard, PIIScanner, SecretScanner
52
+
53
+ guard = Guard(
54
+ input_scanners=[SecretScanner(), PIIScanner()],
55
+ output_scanners=[SecretScanner(), PIIScanner()],
56
+ )
57
+
58
+ # Deterministic local demonstration, not a real model integration.
59
+ result = guard.run("Contact casey@example.org", lambda text: f"Received: {text}")
60
+ print(result.require_text()) # Received: Contact [PII]
61
+ print(result.diagnostics()) # Metadata only; no matched strings or prompt text.
62
+ ```
63
+
64
+ `run` calls your callback only after accepted input checks, then checks the **complete**
65
+ returned string before exposing it. Use `await guard.arun(text, callback)` for async work;
66
+ both sync and async callbacks work there. Provider SDKs are not required by the core.
67
+
68
+ | Check | Default | Scope |
69
+ | --- | --- | --- |
70
+ | `PIIScanner` | redact | ASCII email, contiguous international phone, US SSN shapes |
71
+ | `SecretScanner` | block | Selected GitHub tokens, AWS access-key IDs, PEM private keys |
72
+ | `InvisibleScanner` | warn | Unicode control/format characters except tab and newlines |
73
+ | `LiteralScanner([...])` | block | Configured literal substrings; optional ASCII case folding |
74
+ | `JSONScanner(schema)` | block invalid data | Strict JSON and constrained Draft 2020-12 schemas |
75
+ | `ToolGuard({name: schema})` | block invalid calls | Exact tool names and object argument schemas |
76
+
77
+ No scanners are installed implicitly: `Guard()` permits bounded text. Choose policies for each
78
+ boundary. Heuristic matches are signals, not probabilities or comprehensive protection.
79
+
80
+ ```python
81
+ from guardtrellis import Action, Guard, JSONScanner, LiteralScanner, Stage, ToolGuard
82
+
83
+ guard = Guard(
84
+ retrieval_scanners=[LiteralScanner(["confidential"], action=Action.BLOCK)],
85
+ output_scanners=[JSONScanner({"type": "object", "required": ["answer"]})],
86
+ )
87
+ retrieval = guard.scan("A public reference", stage=Stage.RETRIEVAL)
88
+ # In async code: await guard.ascan("A public reference", stage=Stage.RETRIEVAL)
89
+
90
+ tools = ToolGuard(
91
+ {
92
+ "search": {
93
+ "type": "object",
94
+ "properties": {"query": {"type": "string", "maxLength": 200}},
95
+ "required": ["query"],
96
+ "additionalProperties": False,
97
+ },
98
+ }
99
+ )
100
+ call = tools.validate("search", '{"query":"public documentation"}')
101
+ name, arguments = call.require_call()
102
+ # Your application must still enforce identity, permissions, and execution limits.
103
+ ```
104
+
105
+ `ALLOW`, `WARN`, and `REDACT` expose `result.text`; `BLOCK` and `ERROR` expose `None`.
106
+ `require_text()` / `require_call()` raise a payload-free `Rejected` exception on rejection.
107
+ WARN deliberately permits delivery. Scanner/callback exceptions are errors, never successful
108
+ checks. The first block/error stops its stage. Input rejection prevents the callback entirely.
109
+
110
+ Stages have separate scanner lists: `input_scanners`, `output_scanners`, `retrieval_scanners`,
111
+ and `tool_scanners`. Use `scan(text, stage=Stage.INPUT/OUTPUT/RETRIEVAL/TOOL)` or `ascan`;
112
+ the default stage is `Stage.INPUT`. Retrieval/tool checks must be invoked explicitly;
113
+ `run` does not discover or intercept these operations. `ToolGuard` adds name/schema validation.
114
+
115
+ Scanners run in configuration order. Each sees the text produced by preceding redactions.
116
+ Findings record half-open character offsets, scanner index, and the **input revision** they
117
+ refer to; every redacting scanner increments the revision. Offsets from different revisions
118
+ must not be applied to the original string. No originals or rehydration maps are retained.
119
+
120
+ Defaults: 100,000 characters per stage, 256 findings per scanner, JSON nesting at most 32,
121
+ and a 5-second **per-operation async wait**. Synchronous calls have no execution deadline.
122
+ Async cancellation cannot terminate a running thread or preempt a coroutine that blocks
123
+ the event loop. Timed-out work may continue and have side effects. Use process isolation
124
+ and application concurrency limits when execution must be forcibly bounded.
125
+
126
+ ## Examples and development
127
+
128
+ ```sh
129
+ uv sync --all-extras --group dev
130
+ uv run python examples/plain_callable.py
131
+ uv run python examples/fastapi_app.py # Local TestClient demo, no server needed
132
+ uv run python examples/langgraph_app.py # Local graph, no provider credentials
133
+ uv run pytest
134
+ uv run ruff check .
135
+ uv run ruff format --check .
136
+ uv run mypy
137
+ uv run python evaluation/run.py
138
+ uv build
139
+ uv run python scripts/smoke_dist.py
140
+ ```
141
+
142
+ FastAPI and LangGraph are optional extras (`.[fastapi]`, `.[langgraph]`). LangGraph input
143
+ checks run **before** text enters graph state. The example also checks model output before
144
+ returning it to graph state. Instrumentation around callbacks may still capture raw data.
145
+
146
+ See [API details](https://github.com/sahilmathur254/guardtrellis/blob/main/docs/api.md),
147
+ [limitations and trust boundaries](https://github.com/sahilmathur254/guardtrellis/blob/main/docs/limitations.md),
148
+ [evaluation methodology](https://github.com/sahilmathur254/guardtrellis/blob/main/evaluation/README.md),
149
+ [measured smoke results](https://github.com/sahilmathur254/guardtrellis/blob/main/evaluation/REPORT.md),
150
+ and [contribution guidance](https://github.com/sahilmathur254/guardtrellis/blob/main/CONTRIBUTING.md).
151
+ These checks do not provide comprehensive
152
+ prompt-injection prevention, factual verification, regulatory compliance, or a tool sandbox.
153
+
154
+ ## Roadmap and contributions
155
+
156
+ Use the public [GitHub Project](https://github.com/users/sahilmathur254/projects/3) to find
157
+ ready work and track progress. The [roadmap](https://github.com/sahilmathur254/guardtrellis/blob/main/ROADMAP.md) explains the release milestones,
158
+ dependencies, and longer-term proposals. Start with a
159
+ [good first issue](https://github.com/sahilmathur254/guardtrellis/labels/good%20first%20issue)
160
+ or a [help wanted issue](https://github.com/sahilmathur254/guardtrellis/labels/help%20wanted),
161
+ then follow the [contributor workflow](https://github.com/sahilmathur254/guardtrellis/blob/main/CONTRIBUTING.md).
162
+
163
+ See the [changelog](https://github.com/sahilmathur254/guardtrellis/blob/main/CHANGELOG.md)
164
+ for version-specific behavior and the [release guide](https://github.com/sahilmathur254/guardtrellis/blob/main/docs/releasing.md)
165
+ for packaging checks, TestPyPI rehearsal, and maintainer-approved publication.
@@ -0,0 +1,134 @@
1
+ # GuardTrellis
2
+
3
+ A small Python SDK for local checks around model inputs, complete outputs, retrieved text,
4
+ and proposed tool calls. Policies are explicit, composable, and independent of model providers.
5
+
6
+ **Alpha: 0.1.0a1.** APIs may change before a stable release.
7
+ Supported Python: 3.11–3.14. Apache-2.0 licensed. Verified package availability is tracked
8
+ in the [first alpha release issue](https://github.com/sahilmathur254/guardtrellis/issues/4).
9
+
10
+ Use an activated virtual environment, then clone and install the source:
11
+
12
+ ```sh
13
+ git clone https://github.com/sahilmathur254/guardtrellis.git
14
+ cd guardtrellis
15
+ python -m pip install -e .
16
+ python examples/plain_callable.py
17
+ ```
18
+
19
+ ```python
20
+ from guardtrellis import Guard, PIIScanner, SecretScanner
21
+
22
+ guard = Guard(
23
+ input_scanners=[SecretScanner(), PIIScanner()],
24
+ output_scanners=[SecretScanner(), PIIScanner()],
25
+ )
26
+
27
+ # Deterministic local demonstration, not a real model integration.
28
+ result = guard.run("Contact casey@example.org", lambda text: f"Received: {text}")
29
+ print(result.require_text()) # Received: Contact [PII]
30
+ print(result.diagnostics()) # Metadata only; no matched strings or prompt text.
31
+ ```
32
+
33
+ `run` calls your callback only after accepted input checks, then checks the **complete**
34
+ returned string before exposing it. Use `await guard.arun(text, callback)` for async work;
35
+ both sync and async callbacks work there. Provider SDKs are not required by the core.
36
+
37
+ | Check | Default | Scope |
38
+ | --- | --- | --- |
39
+ | `PIIScanner` | redact | ASCII email, contiguous international phone, US SSN shapes |
40
+ | `SecretScanner` | block | Selected GitHub tokens, AWS access-key IDs, PEM private keys |
41
+ | `InvisibleScanner` | warn | Unicode control/format characters except tab and newlines |
42
+ | `LiteralScanner([...])` | block | Configured literal substrings; optional ASCII case folding |
43
+ | `JSONScanner(schema)` | block invalid data | Strict JSON and constrained Draft 2020-12 schemas |
44
+ | `ToolGuard({name: schema})` | block invalid calls | Exact tool names and object argument schemas |
45
+
46
+ No scanners are installed implicitly: `Guard()` permits bounded text. Choose policies for each
47
+ boundary. Heuristic matches are signals, not probabilities or comprehensive protection.
48
+
49
+ ```python
50
+ from guardtrellis import Action, Guard, JSONScanner, LiteralScanner, Stage, ToolGuard
51
+
52
+ guard = Guard(
53
+ retrieval_scanners=[LiteralScanner(["confidential"], action=Action.BLOCK)],
54
+ output_scanners=[JSONScanner({"type": "object", "required": ["answer"]})],
55
+ )
56
+ retrieval = guard.scan("A public reference", stage=Stage.RETRIEVAL)
57
+ # In async code: await guard.ascan("A public reference", stage=Stage.RETRIEVAL)
58
+
59
+ tools = ToolGuard(
60
+ {
61
+ "search": {
62
+ "type": "object",
63
+ "properties": {"query": {"type": "string", "maxLength": 200}},
64
+ "required": ["query"],
65
+ "additionalProperties": False,
66
+ },
67
+ }
68
+ )
69
+ call = tools.validate("search", '{"query":"public documentation"}')
70
+ name, arguments = call.require_call()
71
+ # Your application must still enforce identity, permissions, and execution limits.
72
+ ```
73
+
74
+ `ALLOW`, `WARN`, and `REDACT` expose `result.text`; `BLOCK` and `ERROR` expose `None`.
75
+ `require_text()` / `require_call()` raise a payload-free `Rejected` exception on rejection.
76
+ WARN deliberately permits delivery. Scanner/callback exceptions are errors, never successful
77
+ checks. The first block/error stops its stage. Input rejection prevents the callback entirely.
78
+
79
+ Stages have separate scanner lists: `input_scanners`, `output_scanners`, `retrieval_scanners`,
80
+ and `tool_scanners`. Use `scan(text, stage=Stage.INPUT/OUTPUT/RETRIEVAL/TOOL)` or `ascan`;
81
+ the default stage is `Stage.INPUT`. Retrieval/tool checks must be invoked explicitly;
82
+ `run` does not discover or intercept these operations. `ToolGuard` adds name/schema validation.
83
+
84
+ Scanners run in configuration order. Each sees the text produced by preceding redactions.
85
+ Findings record half-open character offsets, scanner index, and the **input revision** they
86
+ refer to; every redacting scanner increments the revision. Offsets from different revisions
87
+ must not be applied to the original string. No originals or rehydration maps are retained.
88
+
89
+ Defaults: 100,000 characters per stage, 256 findings per scanner, JSON nesting at most 32,
90
+ and a 5-second **per-operation async wait**. Synchronous calls have no execution deadline.
91
+ Async cancellation cannot terminate a running thread or preempt a coroutine that blocks
92
+ the event loop. Timed-out work may continue and have side effects. Use process isolation
93
+ and application concurrency limits when execution must be forcibly bounded.
94
+
95
+ ## Examples and development
96
+
97
+ ```sh
98
+ uv sync --all-extras --group dev
99
+ uv run python examples/plain_callable.py
100
+ uv run python examples/fastapi_app.py # Local TestClient demo, no server needed
101
+ uv run python examples/langgraph_app.py # Local graph, no provider credentials
102
+ uv run pytest
103
+ uv run ruff check .
104
+ uv run ruff format --check .
105
+ uv run mypy
106
+ uv run python evaluation/run.py
107
+ uv build
108
+ uv run python scripts/smoke_dist.py
109
+ ```
110
+
111
+ FastAPI and LangGraph are optional extras (`.[fastapi]`, `.[langgraph]`). LangGraph input
112
+ checks run **before** text enters graph state. The example also checks model output before
113
+ returning it to graph state. Instrumentation around callbacks may still capture raw data.
114
+
115
+ See [API details](https://github.com/sahilmathur254/guardtrellis/blob/main/docs/api.md),
116
+ [limitations and trust boundaries](https://github.com/sahilmathur254/guardtrellis/blob/main/docs/limitations.md),
117
+ [evaluation methodology](https://github.com/sahilmathur254/guardtrellis/blob/main/evaluation/README.md),
118
+ [measured smoke results](https://github.com/sahilmathur254/guardtrellis/blob/main/evaluation/REPORT.md),
119
+ and [contribution guidance](https://github.com/sahilmathur254/guardtrellis/blob/main/CONTRIBUTING.md).
120
+ These checks do not provide comprehensive
121
+ prompt-injection prevention, factual verification, regulatory compliance, or a tool sandbox.
122
+
123
+ ## Roadmap and contributions
124
+
125
+ Use the public [GitHub Project](https://github.com/users/sahilmathur254/projects/3) to find
126
+ ready work and track progress. The [roadmap](https://github.com/sahilmathur254/guardtrellis/blob/main/ROADMAP.md) explains the release milestones,
127
+ dependencies, and longer-term proposals. Start with a
128
+ [good first issue](https://github.com/sahilmathur254/guardtrellis/labels/good%20first%20issue)
129
+ or a [help wanted issue](https://github.com/sahilmathur254/guardtrellis/labels/help%20wanted),
130
+ then follow the [contributor workflow](https://github.com/sahilmathur254/guardtrellis/blob/main/CONTRIBUTING.md).
131
+
132
+ See the [changelog](https://github.com/sahilmathur254/guardtrellis/blob/main/CHANGELOG.md)
133
+ for version-specific behavior and the [release guide](https://github.com/sahilmathur254/guardtrellis/blob/main/docs/releasing.md)
134
+ for packaging checks, TestPyPI rehearsal, and maintainer-approved publication.