groundgate 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 (56) hide show
  1. groundgate-0.1.0/.gitignore +22 -0
  2. groundgate-0.1.0/CHANGELOG.md +21 -0
  3. groundgate-0.1.0/LICENSE +202 -0
  4. groundgate-0.1.0/PKG-INFO +275 -0
  5. groundgate-0.1.0/README.md +243 -0
  6. groundgate-0.1.0/SPEC.md +226 -0
  7. groundgate-0.1.0/conformance/README.md +23 -0
  8. groundgate-0.1.0/conformance/build.py +756 -0
  9. groundgate-0.1.0/conformance/invalid/document-not-nfc.json +18 -0
  10. groundgate-0.1.0/conformance/invalid/policy-bad-confidence.json +15 -0
  11. groundgate-0.1.0/conformance/invalid/policy-unknown-key.json +15 -0
  12. groundgate-0.1.0/conformance/invalid/schema-bad-bound.json +17 -0
  13. groundgate-0.1.0/conformance/invalid/schema-unknown-key.json +17 -0
  14. groundgate-0.1.0/conformance/invalid/schema-unknown-type.json +17 -0
  15. groundgate-0.1.0/conformance/vectors/01-admitted.json +129 -0
  16. groundgate-0.1.0/conformance/vectors/02-structure.json +135 -0
  17. groundgate-0.1.0/conformance/vectors/03-values.json +198 -0
  18. groundgate-0.1.0/conformance/vectors/04-evidence.json +209 -0
  19. groundgate-0.1.0/conformance/vectors/05-non-ascii.json +106 -0
  20. groundgate-0.1.0/conformance/vectors/06-collisions.json +144 -0
  21. groundgate-0.1.0/conformance/vectors/07-qualifiers.json +273 -0
  22. groundgate-0.1.0/conformance/vectors/08-scale.json +78 -0
  23. groundgate-0.1.0/conformance/vectors/09-verbatim.json +90 -0
  24. groundgate-0.1.0/conformance/vectors/10-confidence.json +94 -0
  25. groundgate-0.1.0/conformance/vectors/11-conflicts.json +140 -0
  26. groundgate-0.1.0/conformance/vectors/12-reanchor.json +131 -0
  27. groundgate-0.1.0/conformance/vectors/13-reanchor-off.json +63 -0
  28. groundgate-0.1.0/conformance/vectors/14-coverage.json +83 -0
  29. groundgate-0.1.0/conformance/vectors/15-combined.json +60 -0
  30. groundgate-0.1.0/conformance/vectors/16-label.json +329 -0
  31. groundgate-0.1.0/pyproject.toml +108 -0
  32. groundgate-0.1.0/src/groundgate/__init__.py +22 -0
  33. groundgate-0.1.0/src/groundgate/adapters/__init__.py +1 -0
  34. groundgate-0.1.0/src/groundgate/adapters/langextract.py +123 -0
  35. groundgate-0.1.0/src/groundgate/admit.py +333 -0
  36. groundgate-0.1.0/src/groundgate/canonical.py +120 -0
  37. groundgate-0.1.0/src/groundgate/cli.py +184 -0
  38. groundgate-0.1.0/src/groundgate/codes.py +36 -0
  39. groundgate-0.1.0/src/groundgate/extract/__init__.py +74 -0
  40. groundgate-0.1.0/src/groundgate/extract/layout.py +128 -0
  41. groundgate-0.1.0/src/groundgate/extract/markup.py +180 -0
  42. groundgate-0.1.0/src/groundgate/extract/pdf.py +210 -0
  43. groundgate-0.1.0/src/groundgate/model.py +213 -0
  44. groundgate-0.1.0/src/groundgate/py.typed +0 -0
  45. groundgate-0.1.0/src/groundgate/report.py +349 -0
  46. groundgate-0.1.0/src/groundgate/text.py +207 -0
  47. groundgate-0.1.0/tests/pdfgen.py +50 -0
  48. groundgate-0.1.0/tests/test_admit.py +181 -0
  49. groundgate-0.1.0/tests/test_canonical.py +81 -0
  50. groundgate-0.1.0/tests/test_conformance.py +63 -0
  51. groundgate-0.1.0/tests/test_extract.py +204 -0
  52. groundgate-0.1.0/tests/test_langextract.py +108 -0
  53. groundgate-0.1.0/tests/test_package.py +38 -0
  54. groundgate-0.1.0/tests/test_readme.py +21 -0
  55. groundgate-0.1.0/tests/test_report.py +189 -0
  56. groundgate-0.1.0/tests/test_text.py +99 -0
@@ -0,0 +1,22 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ .venv-*/
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+ .coverage
9
+ coverage.xml
10
+ htmlcov/
11
+ .mypy_cache/
12
+ .pytest_cache/
13
+ .ruff_cache/
14
+ .DS_Store
15
+ .env
16
+
17
+ # spike raw sources (fetched and hash-verified by spikes/m0_5/fetch.py)
18
+ spikes/*/sources/*.pdf
19
+ spikes/*/sources/*.xml
20
+
21
+ # benchmark downloads (hash-pinned in bench/sources.json)
22
+ bench/.cache/
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ Versions follow [SemVer](https://semver.org). A change to how any candidate is decided is a new
4
+ spec version, and receipts name the spec version they were decided under.
5
+
6
+ ## 0.1.0 (2026-09-29)
7
+
8
+ First release. Implements spec v0.1.
9
+
10
+ - `admit` and `verify`: deterministic admission with ten rejection codes, five flags, required
11
+ field coverage and re-anchoring, and receipts hashed over RFC 8785 canonical JSON.
12
+ - `groundgate extract`: PDF (with `[pdf]`), HTML, XML and text to NFC text, with page and word
13
+ boxes for PDFs. Text a reader can't see is dropped, and superscripts are marked.
14
+ - A LangExtract adapter that checks each extraction's value and unit at the place LangExtract
15
+ aligned it.
16
+ - `groundgate report`: a self-contained HTML review page that re-derives the receipt before it
17
+ renders.
18
+ - 16 conformance vectors and 6 invalid packets, language-neutral, so another implementation can
19
+ prove it agrees.
20
+ - A benchmark on 30 public-domain FDA, NTSB and IRS documents with person-checked gold and seven
21
+ models: [bench/RESULTS.md](https://github.com/mohanraj00/groundgate/blob/main/bench/RESULTS.md).
@@ -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,275 @@
1
+ Metadata-Version: 2.5
2
+ Name: groundgate
3
+ Version: 0.1.0
4
+ Summary: Deterministic admission for LLM-extracted facts: admit, flag for verification, or reject, with receipts.
5
+ Project-URL: Repository, https://github.com/mohanraj00/groundgate
6
+ Project-URL: Documentation, https://github.com/mohanraj00/groundgate/blob/main/docs/guide.md
7
+ Project-URL: Specification, https://github.com/mohanraj00/groundgate/blob/main/SPEC.md
8
+ Project-URL: Changelog, https://github.com/mohanraj00/groundgate/blob/main/CHANGELOG.md
9
+ Project-URL: Issues, https://github.com/mohanraj00/groundgate/issues
10
+ Author: Mohan Raj
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ Keywords: extraction,grounding,langextract,llm,verification
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Classifier: Topic :: Text Processing
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.10
27
+ Provides-Extra: langextract
28
+ Requires-Dist: langextract>=1.0; extra == 'langextract'
29
+ Provides-Extra: pdf
30
+ Requires-Dist: pdfminer-six>=20231228; extra == 'pdf'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # groundgate
34
+
35
+ **LLMs propose facts. groundgate decides which ones you can trust.**
36
+
37
+ groundgate is a deterministic admission layer for LLM document extraction. You give it a
38
+ document, a schema, and the facts an extractor proposed. Every fact comes back with one of three
39
+ outcomes:
40
+
41
+ - **admitted**: every check passed;
42
+ - **needs_verification**: nothing failed, but a person should look, and the decision says where;
43
+ - **rejected**: a check failed, with a stable reason code.
44
+
45
+ Every run writes a receipt with hashes of every input. Anyone can re-derive it byte for byte.
46
+
47
+ ![The groundgate review page for IRS Publication 590-A. Left: a Roth IRA limit flagged QUALIFIED_VALUE because the model cited the spousal-deduction sentence ("more than $236,000"). Right: the source text, with that citation outlined in amber and the correct Roth sentence, admitted, highlighted in green below it.](https://raw.githubusercontent.com/mohanraj00/groundgate/main/docs/report.png)
48
+
49
+ ## Why this exists
50
+
51
+ Grounded extraction tools check that the quoted **text** exists in the source. They don't check
52
+ the **value** you asked for.
53
+
54
+ LangExtract is the clearest example, and a good tool. It aligns each `extraction_text` to the
55
+ source and reports `MATCH_EXACT`, `MATCH_FUZZY` and so on. It never looks at the attributes that
56
+ hold the typed value. So this passes as an exact match:
57
+
58
+ ```text
59
+ extraction_text: "$8,000" found in the source: MATCH_EXACT
60
+ value: "80000" not what the source says
61
+ ```
62
+
63
+ Here is what that looks like on a real document. I ran Gemini 3.6 Flash and GPT-OSS 120B through
64
+ LangExtract on two pages of IRS Publication 590-A. LangExtract aligned all 48 extractions as
65
+ `MATCH_EXACT`. groundgate then:
66
+
67
+ - **rejected** Gemini's reading of a misprinted `$252,0000` as 2,520,000;
68
+ - **flagged** two GPT-OSS facts that took a Roth IRA limit from the spousal-deduction sentence;
69
+ the numbers match, but the text says "more than" where the field says "at least";
70
+ - **listed** a required field both models missed;
71
+ - **admitted** 44 facts, all with the right value.
72
+
73
+ One admitted fact still cites the wrong rule. Its number is correct, its comparator matches, and
74
+ no span check can tell. I checked every decision by hand; the details are in
75
+ [examples/irs-590a](https://github.com/mohanraj00/groundgate/blob/main/examples/irs-590a), which is also the page in the screenshot.
76
+
77
+ I measured the gap on purpose before writing the library. On 51 facts from two public-domain
78
+ government documents, LangExtract's strictest setting (`MATCH_EXACT` only) accepted **100%** of
79
+ planted value and unit errors whose quote was correct. groundgate caught **all** of them and
80
+ rejected **none** of the correct facts. The method and full tables are in
81
+ [spikes/m0_5](https://github.com/mohanraj00/groundgate/blob/main/spikes/m0_5/README.md).
82
+
83
+ To be clear about scale: current models rarely get a value wrong. In the benchmark below, 117 of
84
+ 4,350 real extractions were wrong. The point is not that models are bad. It is that when
85
+ one is wrong, nothing downstream should have to trust it, and every fact that is admitted comes
86
+ with proof you can re-check.
87
+
88
+ LangExtract verifies the text. groundgate verifies the value.
89
+
90
+ ## Benchmark
91
+
92
+ Seven models (Gemini, GPT and Claude, each through its own CLI) ran through LangExtract on 30
93
+ public-domain FDA drug labels, NTSB accident reports and IRS publications, at two chunk sizes. A
94
+ person checked every gold fact. Of 4,350 extractions, 117 were wrong: the wrong value, a value
95
+ for a field the document doesn't state, the wrong unit, or not a number.
96
+
97
+ ![Pooled over all 14 runs: MATCH_EXACT accepted 98% of wrong extractions without review, groundgate 6.8%. MATCH_EXACT rejected 4.6% of correct extractions, groundgate 0.3%. groundgate sent 12% of extractions to a person.](https://raw.githubusercontent.com/mohanraj00/groundgate/main/bench/charts/summary.svg)
98
+
99
+ | | LangExtract, `MATCH_EXACT` | groundgate |
100
+ |---|---:|---:|
101
+ | wrong extractions accepted without review | 98.3% (115/117) | 6.8% (8/117) |
102
+ | correct extractions rejected | 4.6% (194/4,233) | 0.3% (14/4,233) |
103
+ | extractions sent to a person | 0% | 12.1% (526/4,350) |
104
+
105
+ Most catches (84 of 109) were `CONFLICTING_CANDIDATES`: a model proposed two values for a
106
+ single-valued field, and groundgate sent both to review instead of picking one.
107
+
108
+ Six of the 8 that got through are the case groundgate says it cannot catch (see
109
+ [What it does not do](#what-it-does-not-do)). Five models took metoprolol's heart failure maximum
110
+ (200 mg) as the hypertension maximum, and one took lisinopril's renal impairment dose as the usual
111
+ starting dose. Each number is real and cited correctly; it belongs to another condition. The
112
+ other two read levothyroxine's 1.6 mcg/kg/day as a flat 1.6 mcg, which the unit check allows.
113
+ Putting all seven models through one gate caught one more, because when they were wrong they
114
+ mostly agreed.
115
+
116
+ The benchmark also found a bug. When LangExtract's chunker cut "29.97" after "29.", groundgate
117
+ read the span as 29, which its own spec forbids. It's fixed, and three wrong altimeter settings no
118
+ longer get through.
119
+
120
+ Tables and planted-error results: [bench/RESULTS.md](https://github.com/mohanraj00/groundgate/blob/main/bench/RESULTS.md). Method and caveats:
121
+ [bench/README.md](https://github.com/mohanraj00/groundgate/blob/main/bench/README.md).
122
+
123
+ ## Quickstart
124
+
125
+ ```bash
126
+ pip install groundgate
127
+ ```
128
+
129
+ ```python
130
+ import groundgate as gg
131
+
132
+ text = "The IRA contribution limit is $7,000. The deduction phases out above $79,000."
133
+ schema = {
134
+ "fields": {
135
+ "ira_limit": {"type": "integer", "unit": "USD"},
136
+ "phaseout_start": {"type": "integer", "unit": "USD"},
137
+ }
138
+ }
139
+
140
+
141
+ def cite(field, value, quote):
142
+ """A candidate citing the first place `quote` appears, as UTF-8 byte offsets."""
143
+ start = text.encode().index(quote.encode())
144
+ span = {"start": start, "end": start + len(quote.encode()), "text": quote}
145
+ return {"field": field, "value": value, "unit": "USD", "evidence": span}
146
+
147
+
148
+ candidates = [
149
+ cite("ira_limit", "7000", "$7,000"),
150
+ cite("ira_limit", "70000", "$7,000"), # a digit too many
151
+ cite("phaseout_start", "79000", "$79,000"), # "above" is not "at"
152
+ ]
153
+ receipt = gg.admit(text, schema, candidates)
154
+ for d in receipt.decisions:
155
+ print(f"{d.outcome:<19} {d.field:<15} {d.value:<6} {' '.join(d.codes)}".rstrip())
156
+
157
+ print(gg.verify(receipt.to_dict(), text, schema, candidates).ok)
158
+ ```
159
+
160
+ ```text
161
+ needs_verification phaseout_start 79000 QUALIFIED_VALUE
162
+ admitted ira_limit 7000
163
+ rejected ira_limit 70000 VALUE_NOT_IN_EVIDENCE
164
+ True
165
+ ```
166
+
167
+ The core has no dependencies. `groundgate[pdf]` adds pdfminer.six for PDF text, and
168
+ `groundgate[langextract]` installs LangExtract. [docs/guide.md](https://github.com/mohanraj00/groundgate/blob/main/docs/guide.md) covers schemas,
169
+ policies, candidates and the Python API.
170
+
171
+ ### With LangExtract
172
+
173
+ ```python
174
+ import langextract as lx
175
+ from groundgate.adapters.langextract import admit_document
176
+
177
+ result = lx.extract(text_or_documents=text, prompt_description=prompt, examples=examples)
178
+ receipt = admit_document(result, schema)
179
+ ```
180
+
181
+ Each extraction's `value` and `unit` attributes are checked at the place LangExtract aligned its
182
+ `extraction_text`. An extraction LangExtract could not align is rejected `NO_EVIDENCE`.
183
+
184
+ ### From the command line
185
+
186
+ ```bash
187
+ groundgate extract p590a.pdf --pages 1-2 -o doc.txt --layout layout.json
188
+ groundgate admit doc.txt schema.json candidates.json -o receipt.json
189
+ groundgate verify receipt.json doc.txt schema.json candidates.json
190
+ groundgate report receipt.json doc.txt schema.json candidates.json --layout layout.json -o report.html
191
+ ```
192
+
193
+ `extract` turns a PDF, HTML, XML or text file into the NFC text everything else reads, and
194
+ records the page and box of every word. Text a reader can't see (proof marks drawn off the page,
195
+ hidden HTML) is dropped, and superscripts are marked so that 10⁹ reads `10^9`, never `109`. Pass
196
+ `-` as the document to read it from a pipe. `report` refuses to render a receipt that doesn't
197
+ re-derive from its inputs. [examples/irs-590a](https://github.com/mohanraj00/groundgate/blob/main/examples/irs-590a) runs the whole pipeline on an
198
+ IRS publication with cached model output, so it reproduces without an API key.
199
+
200
+ ## What it checks
201
+
202
+ Checks run in a fixed order. The first failure rejects the fact.
203
+
204
+ | Code | Rejects when |
205
+ |---|---|
206
+ | `CANDIDATE_INVALID` | the candidate is malformed |
207
+ | `FIELD_UNKNOWN` | the field is not in the schema |
208
+ | `NULL_STRING_LITERAL` | the value is `"null"`, `"none"`, `"n/a"` |
209
+ | `TYPE_INVALID` | the value does not parse as the field's type |
210
+ | `RANGE_INVALID` | the value is outside the field's bounds |
211
+ | `UNIT_INVALID` | the unit is not the field's unit |
212
+ | `NO_EVIDENCE` | no evidence is cited |
213
+ | `SPAN_INVALID` | the span is outside the document or splits a character |
214
+ | `VALUE_NOT_IN_EVIDENCE` | no number in the span equals the value |
215
+ | `UNIT_NOT_IN_EVIDENCE` | the value is there, but not with the field's unit |
216
+
217
+ A fact that passes every check can still be flagged for a person:
218
+
219
+ | Code | Flags when |
220
+ |---|---|
221
+ | `NON_VERBATIM_EVIDENCE` | the quote differs from the text at the span |
222
+ | `QUALIFIED_VALUE` | "up to", "approximately", "or more" changes the value, and the schema didn't declare it |
223
+ | `SCALE_WORD` | "million", "lakh" and similar follow the value |
224
+ | `LOW_CONFIDENCE` | the extractor's confidence is below the policy minimum |
225
+ | `CONFLICTING_CANDIDATES` | another proposal for the same field has a different value |
226
+
227
+ Number matching is collision-safe. The span `500 mg` inside `1,500 mg` never reads as 500, a span
228
+ that stops at `29.` inside `29.97` never reads as 29, and a malformed number like the `$252,0000`
229
+ printed in IRS Publication 590-A never equals 252,000 or 2,520,000. When a span misses the value
230
+ but its quote occurs exactly once elsewhere with the right value and unit, groundgate moves the
231
+ evidence there and records `EVIDENCE_REANCHORED`.
232
+
233
+ The rules are in [SPEC.md](https://github.com/mohanraj00/groundgate/blob/main/SPEC.md). [conformance/](https://github.com/mohanraj00/groundgate/blob/main/conformance) holds 16 language-neutral
234
+ vectors that pin every code, so another implementation can prove it agrees.
235
+
236
+ ## Receipts
237
+
238
+ ```json
239
+ {"groundgate": "0.1",
240
+ "document": {"id": "irs-p590a-2025-pages-1-2", "sha256": "sha256:387c5991b989..."},
241
+ "schema_sha256": "sha256:...", "policy_sha256": "sha256:...",
242
+ "decisions": [{"candidate_id": "Gemini_3.6_Flash_Medium/0", "field": "ira_limit_2025",
243
+ "outcome": "admitted", "codes": [], "value": "7000", "unit": "USD",
244
+ "evidence": {"start": 2634, "end": 2640}, "candidate_sha256": "sha256:37e4fbb8..."},
245
+ "..."],
246
+ "coverage": [{"field": "roth_phaseout_joint_2026_end", "code": "REQUIRED_FIELD_MISSING"}],
247
+ "summary": {"admitted": 50, "needs_verification": 0, "rejected": 2},
248
+ "receipt_sha256": "sha256:..."}
249
+ ```
250
+
251
+ Hashes are SHA-256 over RFC 8785 canonical JSON, so a receipt means the same thing in any
252
+ language. `groundgate verify` re-runs every decision from the inputs and fails on any difference:
253
+ a changed document, schema, policy, candidate or outcome.
254
+
255
+ ## What it does not do
256
+
257
+ - **It does not judge meaning.** If the model reports a number that really is in the sentence but
258
+ belongs to another field, every span check passes: a model that reads an age-50 limit of $8,000
259
+ as the IRA limit cites a real "$8,000" with the right unit. A second proposer plus
260
+ `CONFLICTING_CANDIDATES` catches it only when the models disagree, and in the benchmark they
261
+ mostly agreed: six of the eight escapes were this case.
262
+ - **No dates, arrays of records, or cross-document checks** in spec v0.1.
263
+ - **No OCR.** Scanned PDFs need a text layer first (for example `ocrmypdf`).
264
+ - **No model calls.** groundgate never asks an LLM whether an LLM was right.
265
+
266
+ ## Status
267
+
268
+ Alpha. groundgate 0.1.0 implements spec v0.1, and a receipt names the spec version it was decided
269
+ under. The next spec version starts from what the benchmark found: values that depend on a
270
+ condition (a dose per indication, a limit per year) and weight-based units. See
271
+ [CHANGELOG.md](https://github.com/mohanraj00/groundgate/blob/main/CHANGELOG.md).
272
+
273
+ ## License
274
+
275
+ Apache-2.0.