groundlens 2.0.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 (182) hide show
  1. groundlens-2.0.0/.gitignore +55 -0
  2. groundlens-2.0.0/LICENSE +201 -0
  3. groundlens-2.0.0/PKG-INFO +310 -0
  4. groundlens-2.0.0/README.md +203 -0
  5. groundlens-2.0.0/benchmarks/data/README.md +48 -0
  6. groundlens-2.0.0/deploy/api/README.md +136 -0
  7. groundlens-2.0.0/pyproject.toml +270 -0
  8. groundlens-2.0.0/src/groundlens/__init__.py +202 -0
  9. groundlens-2.0.0/src/groundlens/_internal/__init__.py +1 -0
  10. groundlens-2.0.0/src/groundlens/_internal/csv_loader.py +150 -0
  11. groundlens-2.0.0/src/groundlens/_internal/embeddings.py +267 -0
  12. groundlens-2.0.0/src/groundlens/_internal/geometry.py +130 -0
  13. groundlens-2.0.0/src/groundlens/_internal/strategies.py +176 -0
  14. groundlens-2.0.0/src/groundlens/_internal/thresholds.py +151 -0
  15. groundlens-2.0.0/src/groundlens/_version.py +25 -0
  16. groundlens-2.0.0/src/groundlens/agents/__init__.py +67 -0
  17. groundlens-2.0.0/src/groundlens/agents/customer_support.py +646 -0
  18. groundlens-2.0.0/src/groundlens/agents/rag.py +93 -0
  19. groundlens-2.0.0/src/groundlens/agents/routing.py +518 -0
  20. groundlens-2.0.0/src/groundlens/agents/specialized.py +592 -0
  21. groundlens-2.0.0/src/groundlens/audit.py +520 -0
  22. groundlens-2.0.0/src/groundlens/audit_record.py +470 -0
  23. groundlens-2.0.0/src/groundlens/calibrate.py +384 -0
  24. groundlens-2.0.0/src/groundlens/canaries.py +540 -0
  25. groundlens-2.0.0/src/groundlens/check.py +289 -0
  26. groundlens-2.0.0/src/groundlens/cli/__init__.py +0 -0
  27. groundlens-2.0.0/src/groundlens/cli/canaries.py +131 -0
  28. groundlens-2.0.0/src/groundlens/cli/main.py +513 -0
  29. groundlens-2.0.0/src/groundlens/compliance.py +505 -0
  30. groundlens-2.0.0/src/groundlens/control.py +399 -0
  31. groundlens-2.0.0/src/groundlens/data/__init__.py +31 -0
  32. groundlens-2.0.0/src/groundlens/data/mu_hat_sentence-t5-large.json +8 -0
  33. groundlens-2.0.0/src/groundlens/data/mu_hat_sentence-t5-large.npy +0 -0
  34. groundlens-2.0.0/src/groundlens/data/reference_pairs.csv +213 -0
  35. groundlens-2.0.0/src/groundlens/determinism.py +468 -0
  36. groundlens-2.0.0/src/groundlens/dgi.py +759 -0
  37. groundlens-2.0.0/src/groundlens/evaluate.py +165 -0
  38. groundlens-2.0.0/src/groundlens/facts/__init__.py +30 -0
  39. groundlens-2.0.0/src/groundlens/facts/config.py +248 -0
  40. groundlens-2.0.0/src/groundlens/facts/extract.py +1092 -0
  41. groundlens-2.0.0/src/groundlens/facts/lexicon.py +849 -0
  42. groundlens-2.0.0/src/groundlens/facts/match.py +621 -0
  43. groundlens-2.0.0/src/groundlens/facts/normalise.py +938 -0
  44. groundlens-2.0.0/src/groundlens/facts/polarity.py +186 -0
  45. groundlens-2.0.0/src/groundlens/geometry/__init__.py +18 -0
  46. groundlens-2.0.0/src/groundlens/geometry/render.py +66 -0
  47. groundlens-2.0.0/src/groundlens/integrations/__init__.py +3 -0
  48. groundlens-2.0.0/src/groundlens/integrations/autogen/__init__.py +12 -0
  49. groundlens-2.0.0/src/groundlens/integrations/autogen/checker.py +195 -0
  50. groundlens-2.0.0/src/groundlens/integrations/crewai/__init__.py +12 -0
  51. groundlens-2.0.0/src/groundlens/integrations/crewai/tool.py +158 -0
  52. groundlens-2.0.0/src/groundlens/integrations/langchain/__init__.py +15 -0
  53. groundlens-2.0.0/src/groundlens/integrations/langchain/callback.py +159 -0
  54. groundlens-2.0.0/src/groundlens/integrations/langchain/evaluator.py +169 -0
  55. groundlens-2.0.0/src/groundlens/integrations/langgraph/__init__.py +38 -0
  56. groundlens-2.0.0/src/groundlens/integrations/langgraph/callback.py +383 -0
  57. groundlens-2.0.0/src/groundlens/integrations/langgraph/report.py +475 -0
  58. groundlens-2.0.0/src/groundlens/integrations/langgraph/trace.py +222 -0
  59. groundlens-2.0.0/src/groundlens/integrations/semantic_kernel/__init__.py +13 -0
  60. groundlens-2.0.0/src/groundlens/integrations/semantic_kernel/filter.py +155 -0
  61. groundlens-2.0.0/src/groundlens/metrics.py +328 -0
  62. groundlens-2.0.0/src/groundlens/packs/__init__.py +70 -0
  63. groundlens-2.0.0/src/groundlens/packs/evaluate.py +521 -0
  64. groundlens-2.0.0/src/groundlens/packs/loader.py +607 -0
  65. groundlens-2.0.0/src/groundlens/packs/predicates.py +457 -0
  66. groundlens-2.0.0/src/groundlens/propose.py +265 -0
  67. groundlens-2.0.0/src/groundlens/providers/__init__.py +15 -0
  68. groundlens-2.0.0/src/groundlens/providers/_base.py +142 -0
  69. groundlens-2.0.0/src/groundlens/providers/anthropic.py +170 -0
  70. groundlens-2.0.0/src/groundlens/providers/google.py +165 -0
  71. groundlens-2.0.0/src/groundlens/providers/hf.py +162 -0
  72. groundlens-2.0.0/src/groundlens/providers/openai.py +168 -0
  73. groundlens-2.0.0/src/groundlens/py.typed +0 -0
  74. groundlens-2.0.0/src/groundlens/rules.py +1683 -0
  75. groundlens-2.0.0/src/groundlens/score.py +130 -0
  76. groundlens-2.0.0/src/groundlens/sgi.py +275 -0
  77. groundlens-2.0.0/src/groundlens/switch.py +310 -0
  78. groundlens-2.0.0/src/groundlens/tools/__init__.py +3 -0
  79. groundlens-2.0.0/src/groundlens/tools/freeze_mu_hat.py +108 -0
  80. groundlens-2.0.0/src/groundlens/types.py +224 -0
  81. groundlens-2.0.0/src/groundlens/verify/__init__.py +76 -0
  82. groundlens-2.0.0/src/groundlens/verify/_base.py +37 -0
  83. groundlens-2.0.0/src/groundlens/verify/detector.py +154 -0
  84. groundlens-2.0.0/src/groundlens/verify/generators.py +184 -0
  85. groundlens-2.0.0/src/groundlens/verify/pipeline.py +71 -0
  86. groundlens-2.0.0/src/groundlens/verify/samplers.py +53 -0
  87. groundlens-2.0.0/src/groundlens/verify/scorers.py +138 -0
  88. groundlens-2.0.0/src/groundlens/verify/two_stage.py +12 -0
  89. groundlens-2.0.0/tests/__init__.py +0 -0
  90. groundlens-2.0.0/tests/conftest.py +172 -0
  91. groundlens-2.0.0/tests/determinism/__init__.py +0 -0
  92. groundlens-2.0.0/tests/determinism/_bootstrap.py +57 -0
  93. groundlens-2.0.0/tests/determinism/_helpers.py +51 -0
  94. groundlens-2.0.0/tests/determinism/_sample.py +233 -0
  95. groundlens-2.0.0/tests/determinism/conftest.py +10 -0
  96. groundlens-2.0.0/tests/determinism/export_golden.py +57 -0
  97. groundlens-2.0.0/tests/determinism/golden/record.json +1 -0
  98. groundlens-2.0.0/tests/determinism/test_audit_chain_v2.py +102 -0
  99. groundlens-2.0.0/tests/determinism/test_canonical_json_stable.py +89 -0
  100. groundlens-2.0.0/tests/determinism/test_golden_record.py +110 -0
  101. groundlens-2.0.0/tests/determinism/test_locale_independence.py +247 -0
  102. groundlens-2.0.0/tests/determinism/test_no_float_in_record.py +98 -0
  103. groundlens-2.0.0/tests/integration/__init__.py +0 -0
  104. groundlens-2.0.0/tests/integration/conftest.py +110 -0
  105. groundlens-2.0.0/tests/integration/golden_scores.json +11 -0
  106. groundlens-2.0.0/tests/integration/test_dgi.py +123 -0
  107. groundlens-2.0.0/tests/integration/test_dgi_inline_calibration.py +106 -0
  108. groundlens-2.0.0/tests/integration/test_encoder_injection.py +279 -0
  109. groundlens-2.0.0/tests/integration/test_evaluate.py +166 -0
  110. groundlens-2.0.0/tests/integration/test_frozen_mu_hat.py +99 -0
  111. groundlens-2.0.0/tests/integration/test_golden_scores.py +344 -0
  112. groundlens-2.0.0/tests/integration/test_sgi.py +136 -0
  113. groundlens-2.0.0/tests/integrations/__init__.py +0 -0
  114. groundlens-2.0.0/tests/integrations/test_autogen.py +114 -0
  115. groundlens-2.0.0/tests/integrations/test_crewai.py +96 -0
  116. groundlens-2.0.0/tests/integrations/test_langchain.py +138 -0
  117. groundlens-2.0.0/tests/integrations/test_langgraph.py +802 -0
  118. groundlens-2.0.0/tests/integrations/test_semantic_kernel.py +102 -0
  119. groundlens-2.0.0/tests/providers/__init__.py +0 -0
  120. groundlens-2.0.0/tests/providers/test_anthropic.py +107 -0
  121. groundlens-2.0.0/tests/providers/test_google.py +126 -0
  122. groundlens-2.0.0/tests/providers/test_openai.py +122 -0
  123. groundlens-2.0.0/tests/unit/__init__.py +0 -0
  124. groundlens-2.0.0/tests/unit/facts/__init__.py +0 -0
  125. groundlens-2.0.0/tests/unit/facts/_stub_determinism.py +50 -0
  126. groundlens-2.0.0/tests/unit/facts/_stub_types.py +91 -0
  127. groundlens-2.0.0/tests/unit/facts/conftest.py +121 -0
  128. groundlens-2.0.0/tests/unit/facts/corpus/obligations_en.yaml +409 -0
  129. groundlens-2.0.0/tests/unit/facts/corpus/obligations_es.yaml +196 -0
  130. groundlens-2.0.0/tests/unit/facts/corpus/values_en.yaml +285 -0
  131. groundlens-2.0.0/tests/unit/facts/corpus/values_es.yaml +144 -0
  132. groundlens-2.0.0/tests/unit/facts/test_cardinals.py +297 -0
  133. groundlens-2.0.0/tests/unit/facts/test_corpus.py +150 -0
  134. groundlens-2.0.0/tests/unit/facts/test_deadline_match.py +182 -0
  135. groundlens-2.0.0/tests/unit/facts/test_determinism.py +229 -0
  136. groundlens-2.0.0/tests/unit/facts/test_extract.py +247 -0
  137. groundlens-2.0.0/tests/unit/facts/test_match.py +388 -0
  138. groundlens-2.0.0/tests/unit/facts/test_normalise.py +365 -0
  139. groundlens-2.0.0/tests/unit/facts/test_obligation_sources.py +223 -0
  140. groundlens-2.0.0/tests/unit/facts/test_polarity.py +439 -0
  141. groundlens-2.0.0/tests/unit/facts/test_polarity_limits.py +176 -0
  142. groundlens-2.0.0/tests/unit/facts/test_robustness.py +117 -0
  143. groundlens-2.0.0/tests/unit/test_agents.py +600 -0
  144. groundlens-2.0.0/tests/unit/test_audit_record_roundtrip.py +280 -0
  145. groundlens-2.0.0/tests/unit/test_calibrate.py +147 -0
  146. groundlens-2.0.0/tests/unit/test_canaries.py +249 -0
  147. groundlens-2.0.0/tests/unit/test_check.py +156 -0
  148. groundlens-2.0.0/tests/unit/test_cli.py +300 -0
  149. groundlens-2.0.0/tests/unit/test_control.py +607 -0
  150. groundlens-2.0.0/tests/unit/test_csv_loader.py +199 -0
  151. groundlens-2.0.0/tests/unit/test_dgi_local.py +53 -0
  152. groundlens-2.0.0/tests/unit/test_dgi_sgi_validation.py +320 -0
  153. groundlens-2.0.0/tests/unit/test_embeddings.py +73 -0
  154. groundlens-2.0.0/tests/unit/test_encoder_defaults.py +60 -0
  155. groundlens-2.0.0/tests/unit/test_evaluate.py +145 -0
  156. groundlens-2.0.0/tests/unit/test_freeze_mu_hat.py +141 -0
  157. groundlens-2.0.0/tests/unit/test_frozen_mu_hat_contract.py +223 -0
  158. groundlens-2.0.0/tests/unit/test_fuzz_targets_are_importable.py +77 -0
  159. groundlens-2.0.0/tests/unit/test_geometry.py +240 -0
  160. groundlens-2.0.0/tests/unit/test_import_isolation.py +154 -0
  161. groundlens-2.0.0/tests/unit/test_no_egress.py +40 -0
  162. groundlens-2.0.0/tests/unit/test_packs.py +650 -0
  163. groundlens-2.0.0/tests/unit/test_propose_labels.py +401 -0
  164. groundlens-2.0.0/tests/unit/test_readme_snippets.py +308 -0
  165. groundlens-2.0.0/tests/unit/test_regressions.py +129 -0
  166. groundlens-2.0.0/tests/unit/test_rules.py +390 -0
  167. groundlens-2.0.0/tests/unit/test_score.py +198 -0
  168. groundlens-2.0.0/tests/unit/test_switch.py +288 -0
  169. groundlens-2.0.0/tests/unit/test_thresholds.py +135 -0
  170. groundlens-2.0.0/tests/unit/test_version_consistency.py +144 -0
  171. groundlens-2.0.0/tests/verify/__init__.py +0 -0
  172. groundlens-2.0.0/tests/verify/test_check_builder.py +37 -0
  173. groundlens-2.0.0/tests/verify/test_detector_logic.py +65 -0
  174. groundlens-2.0.0/tests/verify/test_detector_wiring.py +82 -0
  175. groundlens-2.0.0/tests/verify/test_generators.py +115 -0
  176. groundlens-2.0.0/tests/verify/test_hf_generator.py +64 -0
  177. groundlens-2.0.0/tests/verify/test_import_invariant.py +37 -0
  178. groundlens-2.0.0/tests/verify/test_samplers.py +36 -0
  179. groundlens-2.0.0/tests/verify/test_scorers_logic.py +55 -0
  180. groundlens-2.0.0/tests/verify/test_shim_and_samplers.py +24 -0
  181. groundlens-2.0.0/tests/verify/test_two_stage.py +71 -0
  182. groundlens-2.0.0/tests/verify/test_wikibio_repro.py +48 -0
@@ -0,0 +1,55 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.egg-info/
6
+ *.egg
7
+ dist/
8
+ build/
9
+ *.whl
10
+ .eggs/
11
+
12
+ # Virtual environments
13
+ .venv/
14
+ venv/
15
+ env/
16
+ .env
17
+
18
+ # IDE
19
+ .vscode/
20
+ .idea/
21
+ *.swp
22
+ *.swo
23
+ *~
24
+
25
+ # Testing / Coverage
26
+ .pytest_cache/
27
+ .mypy_cache/
28
+ .ruff_cache/
29
+ htmlcov/
30
+ .coverage
31
+ .coverage.*
32
+ coverage.xml
33
+
34
+ # Documentation
35
+ site/
36
+
37
+ # OS
38
+ .DS_Store
39
+ Thumbs.db
40
+
41
+ # Embedding model cache
42
+ .cache/
43
+
44
+ # Secrets
45
+ *.key
46
+ *.pem
47
+ .env.local
48
+ gl/
49
+ benchmarks/results/
50
+
51
+ # Audit logs written by running the README and docs examples.
52
+ # open_log("audit.db") creates these wherever the snippet is run from.
53
+ audit.db
54
+ *.sqlite
55
+ *.sqlite3
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Javier Marín
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,310 @@
1
+ Metadata-Version: 2.4
2
+ Name: groundlens
3
+ Version: 2.0.0
4
+ Summary: Deterministic, offline checks for normative AI answers: obligation polarity, deadlines, citations and numbers against your evidence and your policy packs.
5
+ Project-URL: Homepage, https://groundlens.dev
6
+ Project-URL: Documentation, https://docs.groundlens.dev
7
+ Project-URL: Repository, https://github.com/groundlens-dev/groundlens
8
+ Project-URL: Issues, https://github.com/groundlens-dev/groundlens/issues
9
+ Project-URL: Changelog, https://github.com/groundlens-dev/groundlens/blob/main/CHANGELOG.md
10
+ Project-URL: Research (SGI), https://arxiv.org/abs/2512.13771
11
+ Project-URL: Research (DGI), https://arxiv.org/pdf/2602.13224v3
12
+ Project-URL: Research (Rotational dynamics), https://arxiv.org/abs/2603.13259
13
+ Author-email: Javier Marin <javier@jmarin.info>
14
+ License-Expression: Apache-2.0
15
+ License-File: LICENSE
16
+ Keywords: ai-safety,dgi,embedding-geometry,eu-ai-act,factual-accuracy,grounding,hallucination-detection,llm-evaluation,rag,sgi
17
+ Classifier: Development Status :: 4 - Beta
18
+ Classifier: Intended Audience :: Developers
19
+ Classifier: Intended Audience :: Science/Research
20
+ Classifier: License :: OSI Approved :: Apache Software License
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Programming Language :: Python :: 3.14
27
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
28
+ Classifier: Topic :: Software Development :: Quality Assurance
29
+ Classifier: Typing :: Typed
30
+ Requires-Python: >=3.10
31
+ Requires-Dist: pyyaml>=6.0
32
+ Provides-Extra: all
33
+ Requires-Dist: accelerate>=0.30.0; extra == 'all'
34
+ Requires-Dist: anthropic>=0.25.0; extra == 'all'
35
+ Requires-Dist: autogen-agentchat>=0.4.0; extra == 'all'
36
+ Requires-Dist: bitsandbytes>=0.43.0; (platform_system == 'Linux') and extra == 'all'
37
+ Requires-Dist: crewai>=0.80.0; extra == 'all'
38
+ Requires-Dist: google-generativeai>=0.5.0; extra == 'all'
39
+ Requires-Dist: langchain-core>=0.3.0; extra == 'all'
40
+ Requires-Dist: langgraph>=0.2.0; extra == 'all'
41
+ Requires-Dist: langsmith>=0.1.0; extra == 'all'
42
+ Requires-Dist: numpy>=1.24.0; extra == 'all'
43
+ Requires-Dist: openai>=1.0.0; extra == 'all'
44
+ Requires-Dist: semantic-kernel>=1.0.0; extra == 'all'
45
+ Requires-Dist: sentence-transformers<6.0.0,>=2.7.0; extra == 'all'
46
+ Requires-Dist: torch>=2.1.0; extra == 'all'
47
+ Requires-Dist: transformers>=4.40.0; extra == 'all'
48
+ Provides-Extra: anthropic
49
+ Requires-Dist: anthropic>=0.25.0; extra == 'anthropic'
50
+ Provides-Extra: autogen
51
+ Requires-Dist: autogen-agentchat>=0.4.0; extra == 'autogen'
52
+ Provides-Extra: benchmark
53
+ Requires-Dist: datasets>=2.14.0; extra == 'benchmark'
54
+ Requires-Dist: numpy>=1.24.0; extra == 'benchmark'
55
+ Requires-Dist: scikit-learn>=1.3.0; extra == 'benchmark'
56
+ Requires-Dist: sentence-transformers<6.0.0,>=2.7.0; extra == 'benchmark'
57
+ Provides-Extra: crewai
58
+ Requires-Dist: crewai>=0.80.0; extra == 'crewai'
59
+ Provides-Extra: dev
60
+ Requires-Dist: mypy>=1.10; extra == 'dev'
61
+ Requires-Dist: numpy>=1.24.0; extra == 'dev'
62
+ Requires-Dist: pip-audit>=2.7; extra == 'dev'
63
+ Requires-Dist: pre-commit>=3.7; extra == 'dev'
64
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
65
+ Requires-Dist: pytest-mock>=3.12; extra == 'dev'
66
+ Requires-Dist: pytest>=8.0; extra == 'dev'
67
+ Requires-Dist: ruff>=0.5.0; extra == 'dev'
68
+ Requires-Dist: sentence-transformers<6.0.0,>=2.7.0; extra == 'dev'
69
+ Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
70
+ Provides-Extra: docs
71
+ Requires-Dist: mkdocs-gen-files>=0.5; extra == 'docs'
72
+ Requires-Dist: mkdocs-literate-nav>=0.6; extra == 'docs'
73
+ Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
74
+ Requires-Dist: mkdocstrings[python]>=0.25; extra == 'docs'
75
+ Provides-Extra: geometry
76
+ Requires-Dist: numpy>=1.24.0; extra == 'geometry'
77
+ Requires-Dist: sentence-transformers<6.0.0,>=2.7.0; extra == 'geometry'
78
+ Provides-Extra: google
79
+ Requires-Dist: google-generativeai>=0.5.0; extra == 'google'
80
+ Provides-Extra: integrations
81
+ Requires-Dist: autogen-agentchat>=0.4.0; extra == 'integrations'
82
+ Requires-Dist: crewai>=0.80.0; extra == 'integrations'
83
+ Requires-Dist: langchain-core>=0.3.0; extra == 'integrations'
84
+ Requires-Dist: langgraph>=0.2.0; extra == 'integrations'
85
+ Requires-Dist: langsmith>=0.1.0; extra == 'integrations'
86
+ Requires-Dist: semantic-kernel>=1.0.0; extra == 'integrations'
87
+ Provides-Extra: langchain
88
+ Requires-Dist: langchain-core>=0.3.0; extra == 'langchain'
89
+ Requires-Dist: langsmith>=0.1.0; extra == 'langchain'
90
+ Provides-Extra: langgraph
91
+ Requires-Dist: langchain-core>=0.3.0; extra == 'langgraph'
92
+ Requires-Dist: langgraph>=0.2.0; extra == 'langgraph'
93
+ Provides-Extra: openai
94
+ Requires-Dist: openai>=1.0.0; extra == 'openai'
95
+ Provides-Extra: providers
96
+ Requires-Dist: anthropic>=0.25.0; extra == 'providers'
97
+ Requires-Dist: google-generativeai>=0.5.0; extra == 'providers'
98
+ Requires-Dist: openai>=1.0.0; extra == 'providers'
99
+ Provides-Extra: semantic-kernel
100
+ Requires-Dist: semantic-kernel>=1.0.0; extra == 'semantic-kernel'
101
+ Provides-Extra: verify
102
+ Requires-Dist: accelerate>=0.30.0; extra == 'verify'
103
+ Requires-Dist: bitsandbytes>=0.43.0; (platform_system == 'Linux') and extra == 'verify'
104
+ Requires-Dist: torch>=2.1.0; extra == 'verify'
105
+ Requires-Dist: transformers>=4.40.0; extra == 'verify'
106
+ Description-Content-Type: text/markdown
107
+
108
+ <div align="center">
109
+
110
+ # Groundlens
111
+
112
+ **Groundlens checks what an answer tells people they have to do.**
113
+
114
+ [![Python](https://img.shields.io/badge/python-3.10%20|%203.11%20|%203.12%20|%203.13%20|%203.14-blue?style=flat-square)](https://github.com/groundlens-dev/groundlens)
115
+ [![CI](https://img.shields.io/github/actions/workflow/status/groundlens-dev/groundlens/ci.yml?branch=main&label=CI&style=flat-square)](https://github.com/groundlens-dev/groundlens/actions)
116
+ [![PyPI](https://img.shields.io/pypi/v/groundlens?style=flat-square&label=version&color=orange)](https://pypi.org/project/groundlens/)
117
+ [![License: Apache](https://img.shields.io/badge/license-Apache%202-green?style=flat-square)](https://www.apache.org/licenses/LICENSE-2.0)
118
+ [![Docs](https://img.shields.io/badge/docs-docs.groundlens.dev-blue?style=flat-square)](https://docs.groundlens.dev)
119
+ [![OpenSSF Scorecard](https://img.shields.io/ossf-scorecard/github.com/groundlens-dev/groundlens?style=flat-square&label=OpenSSF%20Scorecard)](https://scorecard.dev/viewer/?uri=github.com/groundlens-dev/groundlens)
120
+
121
+ [Docs](https://docs.groundlens.dev) · [Migrating from 1.x](MIGRATING.md) · [Rule packs](https://github.com/groundlens-dev/groundlens/tree/main/packs) · [MCP server](https://github.com/groundlens-dev/groundlens-mcp)
122
+
123
+ </div>
124
+
125
+ An answer written from your own documents can still turn a "may" into a "must", move a deadline, restate an amount that no source contains, or cite a section that does not exist. Those sentences are the ones that create an obligation for a customer, a claimant or a patient, and they are the ones a reviewer has to catch.
126
+
127
+ Groundlens pulls those statements out of the answer, compares each one against the sources you supplied and the rules you wrote, and returns one of two decisions: clear, or send this to a person. It runs on your machine. It calls no model. The same inputs give the same decision tomorrow.
128
+
129
+ ## A first check
130
+
131
+ ```python
132
+ from datetime import date
133
+ from groundlens import check
134
+
135
+ result = check(
136
+ "You must call us before you travel abroad. The annual fee is 45,00 EUR.",
137
+ [{"id": "terms.pdf#p2", "text": "The customer may repay the balance early. The annual fee is 30,00 EUR."}],
138
+ ruleset="eu-retail-banking",
139
+ metadata={"product_type": "credit-card", "disclosure_set": "es-2026"},
140
+ reference_date=date(2026, 8, 8),
141
+ )
142
+ print(result.decision.value)
143
+ for finding in result.findings:
144
+ if finding.severity.value == "fail":
145
+ print(finding.rule_id, finding.message)
146
+ ```
147
+
148
+ ```text
149
+ escalate
150
+ BNK-001 The answer says '45,00 EUR' but the source says 'EUR 30'.
151
+ BNK-031 Required disclosure block present.
152
+ BNK-020 The answer tells the reader 'You must call us before you travel abroad', and no source says that.
153
+ ```
154
+
155
+ Two decisions and nothing else. There is no score, no confidence and no threshold, because a number between zero and one invites somebody to move the line later, and a control whose line moves is not a control.
156
+
157
+ ## What it checks
158
+
159
+ Groundlens reads eight kinds of statement out of an answer, each with the exact character span it came from.
160
+
161
+ | Kind | What it picks up | Example of a finding |
162
+ |---|---|---|
163
+ | Obligation | must, must not, may, need not, should | The answer says "must" where the source says "may" |
164
+ | Deadline | within 14 days, by 31 March, before closing | The answer shortens a deadline the source gives |
165
+ | Date | absolute and relative dates | The answer states a date no source contains |
166
+ | Duration | 30 days, six months, business days | The answer counts business days as calendar days |
167
+ | Currency | amounts with a unit | The answer states an amount the source contradicts |
168
+ | Number | bare quantities | The answer states a figure no source contains |
169
+ | Percent | rates and percentage points | The answer confuses a rate with percentage points |
170
+ | Citation | article, section and clause references | The answer cites a section nobody supplied |
171
+
172
+ Obligation polarity is the part no other tool ships. "The customer must notify us" and "the customer may notify us" are two different instructions, and the difference is invisible to a similarity score. Groundlens treats it as a typed, checkable statement, ranks the five strengths, and reports an answer that is firmer than the evidence behind it.
173
+
174
+ On top of that, a rule pack can require named wording, forbid named wording, require a disclosure block, require a citation to resolve to a source you actually passed, and require the caller to declare context such as the product type. A missing declaration is a failure, not a silent pass.
175
+
176
+ ## What it does not do
177
+
178
+ - It does not score truth. If a claim is wrong and every source agrees with it, Groundlens will clear it.
179
+ - It does not read prose for meaning. A defect stated in words it does not extract will pass.
180
+ - It does not cover the input side. Prompt injection, harmful content and jailbreaks are somebody else's job.
181
+ - It does not rank or grade. The output is clear or escalate, per rule, with a span.
182
+ - It only catches what a pack asks for. An empty pack clears everything.
183
+
184
+ ## What this is not
185
+
186
+ Groundlens is narrow on purpose. If your problem is one of these, use the tool that was built for it. Every one of them is good.
187
+
188
+ | You need | Use | Why it is better at this |
189
+ |---|---|---|
190
+ | Which words in this answer are not supported by the retrieved text | [LettuceDetect](https://github.com/KRLabsOrg/LettuceDetect) | MIT, `pip install lettucedetect`, runs offline with no LLM, returns token level spans over the whole answer. This is the general groundedness job and it does it well. |
191
+ | A single number for how well a summary sticks to its source | [Vectara HHEM](https://huggingface.co/vectara/hallucination_evaluation_model) | An open model built and tuned for exactly that score, with a public leaderboard behind it. |
192
+ | Metrics over a test set while you tune a RAG pipeline | [RAGAS](https://github.com/explodinggradients/ragas), [DeepEval](https://github.com/confident-ai/deepeval) | Faithfulness, answer relevancy, context precision, dataset runners, CI reporting. Groundlens has none of that. |
193
+ | A managed service inside your cloud | [Azure AI Content Safety groundedness detection](https://learn.microsoft.com/azure/ai-services/content-safety/concepts/groundedness) | Hosted, supported, no weights to ship, covers input safety too. |
194
+ | Formal proof that a claim follows from an encoded policy | [AWS Bedrock Automated Reasoning checks](https://docs.aws.amazon.com/bedrock/latest/userguide/automated-reasoning.html) | Real logical verification against a policy model, with immutable numbered policy versions. |
195
+ | To measure how often a model hallucinates | [HalluLens](https://github.com/facebookresearch/HalluLens) | A benchmark, which is a different thing from a control in a live pipeline. |
196
+
197
+ Groundlens is not a hallucination detector and does not produce a factual consistency score. Nothing here replaces the tools above. Several teams will want Groundlens next to one of them, not instead of one.
198
+
199
+ ## Install
200
+
201
+ ```bash
202
+ pip install groundlens
203
+ ```
204
+
205
+ The install is small. The only runtime dependency is `pyyaml`. `import groundlens` does not import `torch`, `numpy`, `transformers` or `sentence_transformers`, and there is a test in CI that fails if it ever does.
206
+
207
+ The geometry work described under [Research](#research) is optional and lives behind an extra:
208
+
209
+ ```bash
210
+ pip install "groundlens[geometry]"
211
+ ```
212
+
213
+ Coming from 1.x, read [MIGRATING.md](MIGRATING.md) first. `check()` now means something different.
214
+
215
+ ## Rule packs
216
+
217
+ A pack is a YAML file, never Python. A reviewer who does not write code has to be able to read it, diff two versions of it, and sign the diff.
218
+
219
+ ```yaml
220
+ pack: eu-retail-banking
221
+ version: 1.3.0
222
+ locale_profile: eu-es
223
+ requires_metadata:
224
+ - product_type
225
+ - disclosure_set
226
+ rules:
227
+ - id: BNK-001
228
+ description: Every monetary amount stated must appear in the evidence.
229
+ assert: all_facts_matched
230
+ where: { kind: currency }
231
+ severity: fail
232
+ citation: "EBA/GL/2020/06 §4.2"
233
+
234
+ - id: BNK-020
235
+ description: Obligation strength must not exceed the evidence.
236
+ assert: obligation_polarity_consistent
237
+ severity: fail
238
+ ```
239
+
240
+ Eight assertions are supported and no others: `all_facts_matched`, `no_contradicted_facts`, `absent_lexicon`, `present_lexicon`, `obligation_polarity_consistent`, `citations_resolve`, `metadata_equals` and `predicate`. Adding a ninth is a change to the interface, not a change to a pack.
241
+
242
+ Two packs ship with the library, `eu-retail-banking` and `decision-rationale`. Point `ruleset=` at a name, at a path to your own `pack.yaml`, or at a `Pack` you loaded yourself.
243
+
244
+ ```python
245
+ from groundlens import load_pack
246
+
247
+ pack = load_pack("packs/eu-retail-banking/pack.yaml")
248
+ print(pack.name, pack.version, pack.content_sha256[:12])
249
+ ```
250
+
251
+ The identity of a pack is the SHA-256 of its bytes, taken before parsing. A version label is a string somebody typed. The hash is what binds to behaviour, and the hash is what the record stores.
252
+
253
+ Packs read numbers and dates through `locale_profile`, never through the environment. `1.000,50` is read the Spanish way under `eu-es` on a machine whose locale says otherwise.
254
+
255
+ ## Audit
256
+
257
+ Every call returns a record alongside the decision. It carries hashes of the answer and of each source, the pack name, version and content hash, the counts, and every finding with its span.
258
+
259
+ ```python
260
+ from groundlens.audit import open_log
261
+
262
+ with open_log("audit.db") as log:
263
+ log.record_v2(identifier="case-4471", record=result.audit)
264
+ print(log.verify_chain().valid)
265
+ ```
266
+
267
+ Metadata values never reach the record. Only the key names do, because the values may carry personal data.
268
+
269
+ Two properties follow from the design rather than from a promise. Reruns of the same inputs under the same pack hash produce the same record, byte for byte, because there is no floating point, no wall clock, no environment locale and no randomness in the path. And each log row is hashed against the row before it, so a later edit to the trail is visible.
270
+
271
+ This is a property of the tool. It is not a claim about what any regulation requires of you.
272
+
273
+ ## Research
274
+
275
+ Geometry (SGI and DGI) is where Groundlens started. It measures where an answer sits relative to its question and its source, and it is a useful ranking signal when an answer ignores the document it was given. It is now optional, it is not the product, and it sits behind `pip install "groundlens[geometry]"`.
276
+
277
+ It has a known limit, established in our own work: detectability tracks how closely a wrong answer matches the register of a right one. A wrong value written in exactly the right style is close to invisible to a single frozen sentence embedding. That result is the reason the product moved to typed statements and written rules.
278
+
279
+ Five arXiv preprints. Each has been revised in response to reviews. None is a peer-reviewed publication.
280
+
281
+ | # | Paper | ID |
282
+ |---|-------|-----|
283
+ | 1 | Semantic Grounding Index: Geometric Bounds on Context Engagement in RAG Systems | [arXiv:2512.13771](https://arxiv.org/abs/2512.13771) |
284
+ | 2 | A Geometric Taxonomy of Hallucination in LLMs | [arXiv:2602.13224](https://arxiv.org/abs/2602.13224) |
285
+ | 3 | How Transformers Reject Wrong Answers | [arXiv:2603.13259](https://arxiv.org/abs/2603.13259) |
286
+ | 4 | The Outer Geometry of Truth | preprint |
287
+ | 5 | The Geometry of Validity | preprint |
288
+
289
+ Geometry documentation lives under [docs/research](docs/research/).
290
+
291
+ ## Open core
292
+
293
+ This repository is Apache-2.0. The pieces that tend to matter in a regulated deployment are not all inside a `pip install`: maintained domain packs with frozen canary suites, the evidence a second line of defence asks for, and integration templates with stage ordering and logging already wired. Write to javier@groundlens.dev.
294
+
295
+ ## Citation
296
+
297
+ ```bibtex
298
+ @software{marin_groundlens,
299
+ author = {Marin, Javier},
300
+ title = {Groundlens: deterministic checking of obligations, deadlines and figures in LLM output},
301
+ url = {https://github.com/groundlens-dev/groundlens},
302
+ license = {Apache-2.0}
303
+ }
304
+ ```
305
+
306
+ ## Contributing
307
+
308
+ Issues and pull requests welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
309
+
310
+ Contact: javier@groundlens.dev