warrantai 0.0.1__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.
- warrantai-0.0.1/.gitignore +14 -0
- warrantai-0.0.1/LICENSE +202 -0
- warrantai-0.0.1/PKG-INFO +64 -0
- warrantai-0.0.1/README.md +40 -0
- warrantai-0.0.1/pyproject.toml +43 -0
- warrantai-0.0.1/src/warrant/__init__.py +12 -0
- warrantai-0.0.1/src/warrant/cli.py +70 -0
- warrantai-0.0.1/src/warrant/schema/decision-record.v0.json +166 -0
- warrantai-0.0.1/src/warrant/schema.py +51 -0
- warrantai-0.0.1/tests/test_cli.py +45 -0
- warrantai-0.0.1/tests/test_schema.py +70 -0
warrantai-0.0.1/LICENSE
ADDED
|
@@ -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.
|
warrantai-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: warrantai
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Warrant: the decision ledger for AI agents. Record every consequential agent action with its mandate, evidence, cost and outcome, and replay real decisions before you ship a change.
|
|
5
|
+
Project-URL: Homepage, https://warrantai.dev
|
|
6
|
+
Project-URL: Source, https://github.com/warrant-ai/warrant
|
|
7
|
+
Project-URL: Issues, https://github.com/warrant-ai/warrant/issues
|
|
8
|
+
Author: AI Foundry Ventures
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai-agents,audit,decision-records,governance,llm,observability,policy
|
|
12
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Classifier: Topic :: System :: Logging
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Requires-Dist: jsonschema>=4.18
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
22
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# warrantai
|
|
26
|
+
|
|
27
|
+
Warrant is the decision ledger for AI agents. Every consequential action an agent takes is recorded with the mandate that allowed it, the evidence it used, what it cost, and how it turned out. Developers replay real recorded decisions against a changed prompt, model or policy before shipping. Risk, finance and audit teams get records they can sample and verify without trusting the vendor.
|
|
28
|
+
|
|
29
|
+
This is release 0.0.1. It ships the decision record schema v0 and a validator so the format can be reviewed and integrated against before the SDK lands.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
pip install warrantai
|
|
33
|
+
warrant --version
|
|
34
|
+
warrant schema
|
|
35
|
+
warrant validate examples/loan-approval.json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from warrant import validate, ValidationError
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
validate(record)
|
|
43
|
+
except ValidationError as exc:
|
|
44
|
+
for message in exc.errors:
|
|
45
|
+
print(message)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## What arrives next
|
|
49
|
+
|
|
50
|
+
- `decide()` context manager that opens a record, captures model and tool calls as evidence, and closes it on success or failure, off the hot path
|
|
51
|
+
- `check()` policy evaluation against a cached bundle before the action, with allow, deny or escalate
|
|
52
|
+
- local append-only store with hash chaining and an offline verifier
|
|
53
|
+
- `warrant test`: replay a set of real decisions against a changed target and fail the build on flipped decisions
|
|
54
|
+
- `warrant import`: reconstruct decision records from existing OpenTelemetry trace exports and run policy over them retrospectively
|
|
55
|
+
|
|
56
|
+
Roadmap and schema specification: https://warrantai.dev
|
|
57
|
+
|
|
58
|
+
## Note on the import name
|
|
59
|
+
|
|
60
|
+
The package installs as `warrantai` and imports as `warrant`. An unrelated, unmaintained package named `warrant` (an AWS Cognito helper, last released in 2017) also uses the `warrant` module name. Installing both in one environment will shadow one of them. Uninstall that package if `from warrant import validate` fails.
|
|
61
|
+
|
|
62
|
+
## Licence
|
|
63
|
+
|
|
64
|
+
Apache 2.0.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# warrantai
|
|
2
|
+
|
|
3
|
+
Warrant is the decision ledger for AI agents. Every consequential action an agent takes is recorded with the mandate that allowed it, the evidence it used, what it cost, and how it turned out. Developers replay real recorded decisions against a changed prompt, model or policy before shipping. Risk, finance and audit teams get records they can sample and verify without trusting the vendor.
|
|
4
|
+
|
|
5
|
+
This is release 0.0.1. It ships the decision record schema v0 and a validator so the format can be reviewed and integrated against before the SDK lands.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pip install warrantai
|
|
9
|
+
warrant --version
|
|
10
|
+
warrant schema
|
|
11
|
+
warrant validate examples/loan-approval.json
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
from warrant import validate, ValidationError
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
validate(record)
|
|
19
|
+
except ValidationError as exc:
|
|
20
|
+
for message in exc.errors:
|
|
21
|
+
print(message)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## What arrives next
|
|
25
|
+
|
|
26
|
+
- `decide()` context manager that opens a record, captures model and tool calls as evidence, and closes it on success or failure, off the hot path
|
|
27
|
+
- `check()` policy evaluation against a cached bundle before the action, with allow, deny or escalate
|
|
28
|
+
- local append-only store with hash chaining and an offline verifier
|
|
29
|
+
- `warrant test`: replay a set of real decisions against a changed target and fail the build on flipped decisions
|
|
30
|
+
- `warrant import`: reconstruct decision records from existing OpenTelemetry trace exports and run policy over them retrospectively
|
|
31
|
+
|
|
32
|
+
Roadmap and schema specification: https://warrantai.dev
|
|
33
|
+
|
|
34
|
+
## Note on the import name
|
|
35
|
+
|
|
36
|
+
The package installs as `warrantai` and imports as `warrant`. An unrelated, unmaintained package named `warrant` (an AWS Cognito helper, last released in 2017) also uses the `warrant` module name. Installing both in one environment will shadow one of them. Uninstall that package if `from warrant import validate` fails.
|
|
37
|
+
|
|
38
|
+
## Licence
|
|
39
|
+
|
|
40
|
+
Apache 2.0.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "warrantai"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "Warrant: the decision ledger for AI agents. Record every consequential agent action with its mandate, evidence, cost and outcome, and replay real decisions before you ship a change."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
authors = [{ name = "AI Foundry Ventures" }]
|
|
14
|
+
keywords = ["ai-agents", "audit", "decision-records", "governance", "llm", "observability", "policy"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Topic :: Software Development :: Libraries",
|
|
21
|
+
"Topic :: System :: Logging",
|
|
22
|
+
]
|
|
23
|
+
dependencies = ["jsonschema>=4.18"]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
dev = ["pytest>=8", "build>=1.2"]
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
warrant = "warrant.cli:main"
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://warrantai.dev"
|
|
33
|
+
Source = "https://github.com/warrant-ai/warrant"
|
|
34
|
+
Issues = "https://github.com/warrant-ai/warrant/issues"
|
|
35
|
+
|
|
36
|
+
[tool.hatch.build.targets.wheel]
|
|
37
|
+
packages = ["src/warrant"]
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.sdist]
|
|
40
|
+
include = ["src/warrant", "tests", "README.md", "LICENSE", "pyproject.toml"]
|
|
41
|
+
|
|
42
|
+
[tool.pytest.ini_options]
|
|
43
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Warrant: the decision ledger for AI agents.
|
|
2
|
+
|
|
3
|
+
This release ships the decision record schema v0 and a validator. The SDK's
|
|
4
|
+
``decide()`` context manager, the policy check, the local store and replay
|
|
5
|
+
arrive in the following releases; see https://warrantai.dev.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from warrant.schema import SCHEMA_VERSION, ValidationError, load_schema, validate
|
|
9
|
+
|
|
10
|
+
__version__ = "0.0.1"
|
|
11
|
+
|
|
12
|
+
__all__ = ["SCHEMA_VERSION", "ValidationError", "__version__", "load_schema", "validate"]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""The ``warrant`` command line entry point."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
from typing import List, Optional
|
|
9
|
+
|
|
10
|
+
from warrant import __version__
|
|
11
|
+
from warrant.schema import SCHEMA_VERSION, ValidationError, load_schema, validate
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _cmd_schema(_: argparse.Namespace) -> int:
|
|
15
|
+
json.dump(load_schema(), sys.stdout, indent=2)
|
|
16
|
+
sys.stdout.write("\n")
|
|
17
|
+
return 0
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _cmd_validate(args: argparse.Namespace) -> int:
|
|
21
|
+
failures = 0
|
|
22
|
+
for path in args.files:
|
|
23
|
+
try:
|
|
24
|
+
with open(path, "r", encoding="utf-8") as fh:
|
|
25
|
+
record = json.load(fh)
|
|
26
|
+
except FileNotFoundError:
|
|
27
|
+
print(f"{path}: file not found", file=sys.stderr)
|
|
28
|
+
failures += 1
|
|
29
|
+
continue
|
|
30
|
+
except json.JSONDecodeError as exc:
|
|
31
|
+
print(f"{path}: invalid JSON at line {exc.lineno} column {exc.colno}: {exc.msg}", file=sys.stderr)
|
|
32
|
+
failures += 1
|
|
33
|
+
continue
|
|
34
|
+
try:
|
|
35
|
+
validate(record)
|
|
36
|
+
except ValidationError as exc:
|
|
37
|
+
failures += 1
|
|
38
|
+
print(f"{path}: INVALID", file=sys.stderr)
|
|
39
|
+
for message in exc.errors:
|
|
40
|
+
print(f" {message}", file=sys.stderr)
|
|
41
|
+
continue
|
|
42
|
+
print(f"{path}: valid (schema v{SCHEMA_VERSION})")
|
|
43
|
+
return 1 if failures else 0
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
47
|
+
parser = argparse.ArgumentParser(prog="warrant", description="Warrant: the decision ledger for AI agents.")
|
|
48
|
+
parser.add_argument("--version", action="version", version=f"warrant {__version__} (schema v{SCHEMA_VERSION})")
|
|
49
|
+
sub = parser.add_subparsers(dest="command")
|
|
50
|
+
|
|
51
|
+
schema = sub.add_parser("schema", help="print the decision record JSON Schema")
|
|
52
|
+
schema.set_defaults(func=_cmd_schema)
|
|
53
|
+
|
|
54
|
+
val = sub.add_parser("validate", help="validate one or more decision record JSON files")
|
|
55
|
+
val.add_argument("files", nargs="+", metavar="FILE")
|
|
56
|
+
val.set_defaults(func=_cmd_validate)
|
|
57
|
+
return parser
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def main(argv: Optional[List[str]] = None) -> int:
|
|
61
|
+
parser = build_parser()
|
|
62
|
+
args = parser.parse_args(argv)
|
|
63
|
+
if not getattr(args, "func", None):
|
|
64
|
+
parser.print_help()
|
|
65
|
+
return 2
|
|
66
|
+
return args.func(args)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
sys.exit(main())
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://warrantai.dev/schema/decision-record.v0.json",
|
|
4
|
+
"title": "Warrant decision record",
|
|
5
|
+
"description": "One consequential action taken by an AI agent, with the mandate that allowed it, the evidence used, the cost, and the outcome once known. Records are append-only; outcomes, human verdicts and corrections are separate records that reference the original decision.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": ["record_id", "record_type", "tenant", "stream", "timestamp", "schema_version", "origin"],
|
|
9
|
+
"properties": {
|
|
10
|
+
"record_id": { "$ref": "#/$defs/ulid" },
|
|
11
|
+
"record_type": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"enum": ["decision", "outcome", "human_verdict", "correction"]
|
|
14
|
+
},
|
|
15
|
+
"tenant": { "type": "string", "minLength": 1 },
|
|
16
|
+
"stream": { "type": "string", "minLength": 1 },
|
|
17
|
+
"timestamp": { "type": "string", "format": "date-time" },
|
|
18
|
+
"sequence": { "type": "integer", "minimum": 0 },
|
|
19
|
+
"schema_version": { "type": "string", "const": "0" },
|
|
20
|
+
"origin": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"enum": ["live", "imported"],
|
|
23
|
+
"description": "live: emitted by the SDK at decision time. imported: reconstructed from an existing trace export by `warrant import`; never presented as sealed live evidence."
|
|
24
|
+
},
|
|
25
|
+
"references": {
|
|
26
|
+
"type": "object",
|
|
27
|
+
"additionalProperties": false,
|
|
28
|
+
"required": ["decision_record_id"],
|
|
29
|
+
"properties": {
|
|
30
|
+
"decision_record_id": { "$ref": "#/$defs/ulid" }
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"actor": {
|
|
34
|
+
"type": "object",
|
|
35
|
+
"additionalProperties": false,
|
|
36
|
+
"required": ["name", "version"],
|
|
37
|
+
"properties": {
|
|
38
|
+
"name": { "type": "string", "minLength": 1 },
|
|
39
|
+
"version": { "type": "string", "minLength": 1 },
|
|
40
|
+
"instance": { "type": "string" },
|
|
41
|
+
"on_behalf_of": { "type": "string", "description": "The human or system principal the agent acts for." }
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"decision": {
|
|
45
|
+
"type": "object",
|
|
46
|
+
"additionalProperties": false,
|
|
47
|
+
"required": ["class", "action", "subject"],
|
|
48
|
+
"properties": {
|
|
49
|
+
"class": { "type": "string", "pattern": "^[a-z0-9_]+(\\.[a-z0-9_]+)*$", "description": "Customer-defined taxonomy, e.g. credit.approve" },
|
|
50
|
+
"action": { "type": "string", "minLength": 1 },
|
|
51
|
+
"subject": { "type": "string", "minLength": 1 },
|
|
52
|
+
"summary": { "type": "string" },
|
|
53
|
+
"alternatives": { "type": "array", "items": { "type": "string" } }
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"mandate": {
|
|
57
|
+
"type": "object",
|
|
58
|
+
"additionalProperties": false,
|
|
59
|
+
"required": ["result"],
|
|
60
|
+
"properties": {
|
|
61
|
+
"policy_id": { "type": "string" },
|
|
62
|
+
"policy_version": { "type": "string" },
|
|
63
|
+
"clause": { "type": "string" },
|
|
64
|
+
"result": { "type": "string", "enum": ["allow", "deny", "escalate", "unchecked"] }
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"evidence": {
|
|
68
|
+
"type": "array",
|
|
69
|
+
"items": {
|
|
70
|
+
"type": "object",
|
|
71
|
+
"additionalProperties": false,
|
|
72
|
+
"required": ["type", "uri", "content_hash"],
|
|
73
|
+
"properties": {
|
|
74
|
+
"type": { "type": "string", "enum": ["model_call", "tool_call", "document", "web", "other"] },
|
|
75
|
+
"uri": { "type": "string", "minLength": 1 },
|
|
76
|
+
"content_hash": { "$ref": "#/$defs/sha256" },
|
|
77
|
+
"retrieved_at": { "type": "string", "format": "date-time" },
|
|
78
|
+
"excerpt": { "type": "string", "description": "Opt-in, redacted before leaving the process." }
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"human": {
|
|
83
|
+
"type": "object",
|
|
84
|
+
"additionalProperties": false,
|
|
85
|
+
"required": ["required"],
|
|
86
|
+
"properties": {
|
|
87
|
+
"required": { "type": "boolean" },
|
|
88
|
+
"reviewer": { "type": "string" },
|
|
89
|
+
"verdict": { "type": "string", "enum": ["approve", "reject", "amend"] },
|
|
90
|
+
"at": { "type": "string", "format": "date-time" },
|
|
91
|
+
"note": { "type": "string" }
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"cost": {
|
|
95
|
+
"type": "object",
|
|
96
|
+
"additionalProperties": false,
|
|
97
|
+
"required": ["amount", "currency"],
|
|
98
|
+
"properties": {
|
|
99
|
+
"amount": { "type": "number", "minimum": 0 },
|
|
100
|
+
"currency": { "type": "string", "pattern": "^[A-Z]{3}$" },
|
|
101
|
+
"cost_centre": { "type": "string" },
|
|
102
|
+
"breakdown": {
|
|
103
|
+
"type": "array",
|
|
104
|
+
"items": {
|
|
105
|
+
"type": "object",
|
|
106
|
+
"additionalProperties": false,
|
|
107
|
+
"required": ["kind", "amount"],
|
|
108
|
+
"properties": {
|
|
109
|
+
"kind": { "type": "string", "enum": ["model_call", "tool_call", "other"] },
|
|
110
|
+
"provider": { "type": "string" },
|
|
111
|
+
"model": { "type": "string" },
|
|
112
|
+
"tokens_in": { "type": "integer", "minimum": 0 },
|
|
113
|
+
"tokens_out": { "type": "integer", "minimum": 0 },
|
|
114
|
+
"amount": { "type": "number", "minimum": 0 }
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"outcome": {
|
|
121
|
+
"type": "object",
|
|
122
|
+
"additionalProperties": false,
|
|
123
|
+
"required": ["status"],
|
|
124
|
+
"properties": {
|
|
125
|
+
"status": { "type": "string", "enum": ["pending", "observed"] },
|
|
126
|
+
"label": { "type": "string" },
|
|
127
|
+
"score": { "type": "number" },
|
|
128
|
+
"observed_at": { "type": "string", "format": "date-time" },
|
|
129
|
+
"source": { "type": "string" }
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
"seal": {
|
|
133
|
+
"type": "object",
|
|
134
|
+
"additionalProperties": false,
|
|
135
|
+
"required": ["prev_hash", "hash"],
|
|
136
|
+
"properties": {
|
|
137
|
+
"prev_hash": { "oneOf": [{ "$ref": "#/$defs/sha256" }, { "type": "null" }], "description": "null only for the first record in a stream." },
|
|
138
|
+
"hash": { "$ref": "#/$defs/sha256" },
|
|
139
|
+
"checkpoint": { "type": "integer", "minimum": 0 },
|
|
140
|
+
"signature": { "type": "string", "description": "Ed25519 signature over hash, base64." }
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
"allOf": [
|
|
145
|
+
{
|
|
146
|
+
"if": { "properties": { "record_type": { "const": "decision" } } },
|
|
147
|
+
"then": { "required": ["actor", "decision", "mandate"] }
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"if": { "properties": { "record_type": { "const": "outcome" } } },
|
|
151
|
+
"then": { "required": ["references", "outcome"] }
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"if": { "properties": { "record_type": { "const": "human_verdict" } } },
|
|
155
|
+
"then": { "required": ["references", "human"] }
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"if": { "properties": { "record_type": { "const": "correction" } } },
|
|
159
|
+
"then": { "required": ["references"] }
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
"$defs": {
|
|
163
|
+
"ulid": { "type": "string", "pattern": "^[0-9A-HJKMNP-TV-Z]{26}$" },
|
|
164
|
+
"sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""Load and validate Warrant decision records against the published schema."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from importlib import resources
|
|
7
|
+
from typing import Any, Dict, List
|
|
8
|
+
|
|
9
|
+
from jsonschema import Draft202012Validator
|
|
10
|
+
from jsonschema.exceptions import ValidationError as _JsonSchemaError
|
|
11
|
+
|
|
12
|
+
SCHEMA_VERSION = "0"
|
|
13
|
+
_SCHEMA_FILE = f"decision-record.v{SCHEMA_VERSION}.json"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ValidationError(ValueError):
|
|
17
|
+
"""A record does not conform to the decision record schema.
|
|
18
|
+
|
|
19
|
+
``errors`` holds one human-readable message per violation, each prefixed
|
|
20
|
+
with the JSON path of the offending field.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(self, errors: List[str]) -> None:
|
|
24
|
+
self.errors = errors
|
|
25
|
+
super().__init__("; ".join(errors))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def load_schema() -> Dict[str, Any]:
|
|
29
|
+
"""Return the decision record JSON Schema shipped with this package."""
|
|
30
|
+
text = resources.files("warrant").joinpath("schema", _SCHEMA_FILE).read_text(encoding="utf-8")
|
|
31
|
+
return json.loads(text)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
_validator = Draft202012Validator(load_schema())
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _describe(error: _JsonSchemaError) -> str:
|
|
38
|
+
path = "/".join(str(p) for p in error.absolute_path) or "(root)"
|
|
39
|
+
return f"{path}: {error.message}"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def validate(record: Any) -> None:
|
|
43
|
+
"""Raise ``ValidationError`` listing every violation, or return ``None`` if valid.
|
|
44
|
+
|
|
45
|
+
``record`` is expected to be the parsed JSON object, not a string.
|
|
46
|
+
"""
|
|
47
|
+
if not isinstance(record, dict):
|
|
48
|
+
raise ValidationError([f"(root): expected an object, got {type(record).__name__}"])
|
|
49
|
+
errors = sorted(_validator.iter_errors(record), key=lambda e: list(e.absolute_path))
|
|
50
|
+
if errors:
|
|
51
|
+
raise ValidationError([_describe(e) for e in errors])
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from warrant.cli import main
|
|
5
|
+
|
|
6
|
+
ROOT = Path(__file__).resolve().parents[2]
|
|
7
|
+
EXAMPLE = ROOT / "examples" / "loan-approval.json"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_schema_command_prints_schema(capsys):
|
|
11
|
+
assert main(["schema"]) == 0
|
|
12
|
+
out = json.loads(capsys.readouterr().out)
|
|
13
|
+
assert out["title"] == "Warrant decision record"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_validate_valid_file(capsys):
|
|
17
|
+
assert main(["validate", str(EXAMPLE)]) == 0
|
|
18
|
+
assert "valid" in capsys.readouterr().out
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_validate_invalid_file(tmp_path, capsys):
|
|
22
|
+
record = json.loads(EXAMPLE.read_text(encoding="utf-8"))
|
|
23
|
+
record["origin"] = "guessed"
|
|
24
|
+
bad = tmp_path / "bad.json"
|
|
25
|
+
bad.write_text(json.dumps(record), encoding="utf-8")
|
|
26
|
+
assert main(["validate", str(bad)]) == 1
|
|
27
|
+
err = capsys.readouterr().err
|
|
28
|
+
assert "INVALID" in err and "origin" in err
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_validate_missing_file(capsys):
|
|
32
|
+
assert main(["validate", str(Path("/nonexistent/record.json"))]) == 1
|
|
33
|
+
assert "file not found" in capsys.readouterr().err
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_validate_malformed_json(tmp_path, capsys):
|
|
37
|
+
bad = tmp_path / "bad.json"
|
|
38
|
+
bad.write_text("{not json", encoding="utf-8")
|
|
39
|
+
assert main(["validate", str(bad)]) == 1
|
|
40
|
+
assert "invalid JSON" in capsys.readouterr().err
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_no_command_prints_help(capsys):
|
|
44
|
+
assert main([]) == 2
|
|
45
|
+
assert "usage: warrant" in capsys.readouterr().out
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from warrant import SCHEMA_VERSION, ValidationError, __version__, load_schema, validate
|
|
7
|
+
|
|
8
|
+
ROOT = Path(__file__).resolve().parents[2]
|
|
9
|
+
EXAMPLES = ROOT / "examples"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _example(name: str) -> dict:
|
|
13
|
+
return json.loads((EXAMPLES / name).read_text(encoding="utf-8"))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_version_is_set():
|
|
17
|
+
assert __version__ == "0.0.1"
|
|
18
|
+
assert SCHEMA_VERSION == "0"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_packaged_schema_matches_canonical_copy():
|
|
22
|
+
canonical = ROOT / "schema" / "decision-record.v0.json"
|
|
23
|
+
if not canonical.exists():
|
|
24
|
+
pytest.skip("canonical schema only present in the source checkout")
|
|
25
|
+
assert load_schema() == json.loads(canonical.read_text(encoding="utf-8"))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_loan_approval_example_is_valid():
|
|
29
|
+
validate(_example("loan-approval.json"))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_loan_outcome_example_is_valid():
|
|
33
|
+
validate(_example("loan-outcome.json"))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_decision_without_mandate_is_rejected():
|
|
37
|
+
record = _example("loan-approval.json")
|
|
38
|
+
del record["mandate"]
|
|
39
|
+
with pytest.raises(ValidationError) as exc:
|
|
40
|
+
validate(record)
|
|
41
|
+
assert any("mandate" in m for m in exc.value.errors)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_unknown_mandate_result_is_rejected():
|
|
45
|
+
record = _example("loan-approval.json")
|
|
46
|
+
record["mandate"]["result"] = "maybe"
|
|
47
|
+
with pytest.raises(ValidationError) as exc:
|
|
48
|
+
validate(record)
|
|
49
|
+
assert any(m.startswith("mandate/result") for m in exc.value.errors)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_outcome_without_reference_is_rejected():
|
|
53
|
+
record = _example("loan-outcome.json")
|
|
54
|
+
del record["references"]
|
|
55
|
+
with pytest.raises(ValidationError) as exc:
|
|
56
|
+
validate(record)
|
|
57
|
+
assert any("references" in m for m in exc.value.errors)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_unknown_top_level_field_is_rejected():
|
|
61
|
+
record = _example("loan-approval.json")
|
|
62
|
+
record["notes"] = "free text"
|
|
63
|
+
with pytest.raises(ValidationError) as exc:
|
|
64
|
+
validate(record)
|
|
65
|
+
assert any("notes" in m for m in exc.value.errors)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_non_object_is_rejected():
|
|
69
|
+
with pytest.raises(ValidationError):
|
|
70
|
+
validate(["not", "a", "record"])
|