factlang 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 (234) hide show
  1. factlang-0.1.0/.gitignore +18 -0
  2. factlang-0.1.0/CHANGELOG.md +68 -0
  3. factlang-0.1.0/LICENSE +21 -0
  4. factlang-0.1.0/PKG-INFO +283 -0
  5. factlang-0.1.0/README.md +198 -0
  6. factlang-0.1.0/docs/agents.md +95 -0
  7. factlang-0.1.0/docs/cli.md +111 -0
  8. factlang-0.1.0/docs/extending/catalogs.md +74 -0
  9. factlang-0.1.0/docs/extending/connectors.md +92 -0
  10. factlang-0.1.0/docs/extending/dialects.md +78 -0
  11. factlang-0.1.0/docs/extending/fragments.md +97 -0
  12. factlang-0.1.0/docs/extending/packs.md +76 -0
  13. factlang-0.1.0/docs/extending/primitives.md +112 -0
  14. factlang-0.1.0/docs/extending/types.md +61 -0
  15. factlang-0.1.0/docs/extending/verbs.md +157 -0
  16. factlang-0.1.0/docs/getting-started.md +198 -0
  17. factlang-0.1.0/docs/guide/batching.md +78 -0
  18. factlang-0.1.0/docs/guide/evidence.md +70 -0
  19. factlang-0.1.0/docs/guide/filters.md +85 -0
  20. factlang-0.1.0/docs/guide/language.md +115 -0
  21. factlang-0.1.0/docs/guide/measure.md +232 -0
  22. factlang-0.1.0/docs/guide/namespaces.md +59 -0
  23. factlang-0.1.0/docs/guide/verbs.md +156 -0
  24. factlang-0.1.0/docs/guide/verdicts.md +84 -0
  25. factlang-0.1.0/docs/index.md +196 -0
  26. factlang-0.1.0/docs/overrides/home.html +88 -0
  27. factlang-0.1.0/docs/playground.md +64 -0
  28. factlang-0.1.0/docs/reference/api.md +194 -0
  29. factlang-0.1.0/docs/reference/diagnostics.md +100 -0
  30. factlang-0.1.0/docs/reference/grammar.md +621 -0
  31. factlang-0.1.0/docs/reference/verbs.md +621 -0
  32. factlang-0.1.0/docs/wiki/Agent-Integration.md +65 -0
  33. factlang-0.1.0/docs/wiki/Analyzer.md +41 -0
  34. factlang-0.1.0/docs/wiki/Architecture.md +106 -0
  35. factlang-0.1.0/docs/wiki/CLI.md +61 -0
  36. factlang-0.1.0/docs/wiki/Catalogs.md +41 -0
  37. factlang-0.1.0/docs/wiki/Concepts.md +68 -0
  38. factlang-0.1.0/docs/wiki/Connectors.md +55 -0
  39. factlang-0.1.0/docs/wiki/Contributing.md +55 -0
  40. factlang-0.1.0/docs/wiki/Design-Decisions.md +81 -0
  41. factlang-0.1.0/docs/wiki/Diagnostics.md +91 -0
  42. factlang-0.1.0/docs/wiki/Dialects.md +73 -0
  43. factlang-0.1.0/docs/wiki/Extending-Catalogs.md +39 -0
  44. factlang-0.1.0/docs/wiki/Extending-Connectors.md +44 -0
  45. factlang-0.1.0/docs/wiki/Extending-Dialects.md +41 -0
  46. factlang-0.1.0/docs/wiki/Extending-Packs.md +42 -0
  47. factlang-0.1.0/docs/wiki/Extending-Verbs.md +87 -0
  48. factlang-0.1.0/docs/wiki/FAQ.md +40 -0
  49. factlang-0.1.0/docs/wiki/Glossary.md +45 -0
  50. factlang-0.1.0/docs/wiki/Home.md +67 -0
  51. factlang-0.1.0/docs/wiki/IR.md +56 -0
  52. factlang-0.1.0/docs/wiki/Judge.md +46 -0
  53. factlang-0.1.0/docs/wiki/Language-Guide.md +115 -0
  54. factlang-0.1.0/docs/wiki/Lexer.md +51 -0
  55. factlang-0.1.0/docs/wiki/Measurement-API.md +101 -0
  56. factlang-0.1.0/docs/wiki/Optimizer.md +42 -0
  57. factlang-0.1.0/docs/wiki/Parser.md +46 -0
  58. factlang-0.1.0/docs/wiki/Standard-Verbs.md +80 -0
  59. factlang-0.1.0/docs/wiki/_Sidebar.md +42 -0
  60. factlang-0.1.0/docs/wiki/sqlglot-Bridge.md +38 -0
  61. factlang-0.1.0/pyproject.toml +145 -0
  62. factlang-0.1.0/scripts/gen_reference.py +151 -0
  63. factlang-0.1.0/site-playground/glue.py +106 -0
  64. factlang-0.1.0/src/factlang/__about__.py +4 -0
  65. factlang-0.1.0/src/factlang/__init__.py +113 -0
  66. factlang-0.1.0/src/factlang/__main__.py +5 -0
  67. factlang-0.1.0/src/factlang/agent/__init__.py +10 -0
  68. factlang-0.1.0/src/factlang/agent/mcp.py +206 -0
  69. factlang-0.1.0/src/factlang/agent/reference.py +122 -0
  70. factlang-0.1.0/src/factlang/agent/tools.py +258 -0
  71. factlang-0.1.0/src/factlang/api.py +207 -0
  72. factlang-0.1.0/src/factlang/cli.py +499 -0
  73. factlang-0.1.0/src/factlang/connectors/__init__.py +44 -0
  74. factlang-0.1.0/src/factlang/connectors/base.py +475 -0
  75. factlang-0.1.0/src/factlang/connectors/bigquery.py +135 -0
  76. factlang-0.1.0/src/factlang/connectors/callable.py +49 -0
  77. factlang-0.1.0/src/factlang/connectors/catalog.py +134 -0
  78. factlang-0.1.0/src/factlang/connectors/dbapi.py +180 -0
  79. factlang-0.1.0/src/factlang/connectors/sqlalchemy.py +104 -0
  80. factlang-0.1.0/src/factlang/contract.py +603 -0
  81. factlang-0.1.0/src/factlang/diagnostics.py +141 -0
  82. factlang-0.1.0/src/factlang/engine.py +865 -0
  83. factlang-0.1.0/src/factlang/ir/__init__.py +52 -0
  84. factlang-0.1.0/src/factlang/ir/metrics.py +61 -0
  85. factlang-0.1.0/src/factlang/ir/primitives.py +462 -0
  86. factlang-0.1.0/src/factlang/judge/__init__.py +41 -0
  87. factlang-0.1.0/src/factlang/judge/outcome.py +111 -0
  88. factlang-0.1.0/src/factlang/judge/predicate.py +369 -0
  89. factlang-0.1.0/src/factlang/judge/run.py +80 -0
  90. factlang-0.1.0/src/factlang/optimizer.py +182 -0
  91. factlang-0.1.0/src/factlang/packs/__init__.py +3 -0
  92. factlang-0.1.0/src/factlang/packs/standard/__init__.py +46 -0
  93. factlang-0.1.0/src/factlang/packs/standard/_common.py +131 -0
  94. factlang-0.1.0/src/factlang/packs/standard/avg.py +58 -0
  95. factlang-0.1.0/src/factlang/packs/standard/count.py +56 -0
  96. factlang-0.1.0/src/factlang/packs/standard/dead.py +40 -0
  97. factlang-0.1.0/src/factlang/packs/standard/distinct.py +58 -0
  98. factlang-0.1.0/src/factlang/packs/standard/exists.py +56 -0
  99. factlang-0.1.0/src/factlang/packs/standard/fanout.py +50 -0
  100. factlang-0.1.0/src/factlang/packs/standard/fresh.py +67 -0
  101. factlang-0.1.0/src/factlang/packs/standard/join.py +173 -0
  102. factlang-0.1.0/src/factlang/packs/standard/max.py +61 -0
  103. factlang-0.1.0/src/factlang/packs/standard/min.py +61 -0
  104. factlang-0.1.0/src/factlang/packs/standard/note.py +45 -0
  105. factlang-0.1.0/src/factlang/packs/standard/nulls.py +53 -0
  106. factlang-0.1.0/src/factlang/packs/standard/pattern.py +54 -0
  107. factlang-0.1.0/src/factlang/packs/standard/range.py +100 -0
  108. factlang-0.1.0/src/factlang/packs/standard/rows.py +47 -0
  109. factlang-0.1.0/src/factlang/packs/standard/sum.py +58 -0
  110. factlang-0.1.0/src/factlang/packs/standard/type.py +54 -0
  111. factlang-0.1.0/src/factlang/packs/standard/unique.py +49 -0
  112. factlang-0.1.0/src/factlang/packs/standard/values.py +90 -0
  113. factlang-0.1.0/src/factlang/py.typed +0 -0
  114. factlang-0.1.0/src/factlang/semantics/__init__.py +1 -0
  115. factlang-0.1.0/src/factlang/semantics/analyzer.py +713 -0
  116. factlang-0.1.0/src/factlang/semantics/catalog.py +130 -0
  117. factlang-0.1.0/src/factlang/semantics/checked.py +79 -0
  118. factlang-0.1.0/src/factlang/semantics/filters.py +165 -0
  119. factlang-0.1.0/src/factlang/semantics/identity.py +107 -0
  120. factlang-0.1.0/src/factlang/semantics/refs.py +45 -0
  121. factlang-0.1.0/src/factlang/semantics/signature.py +140 -0
  122. factlang-0.1.0/src/factlang/semantics/types.py +297 -0
  123. factlang-0.1.0/src/factlang/sql/__init__.py +44 -0
  124. factlang-0.1.0/src/factlang/sql/ast.py +491 -0
  125. factlang-0.1.0/src/factlang/sql/fragment.py +163 -0
  126. factlang-0.1.0/src/factlang/sql/lower.py +529 -0
  127. factlang-0.1.0/src/factlang/sql/printer.py +398 -0
  128. factlang-0.1.0/src/factlang/sql/probe.py +190 -0
  129. factlang-0.1.0/src/factlang/sql/profile.py +317 -0
  130. factlang-0.1.0/src/factlang/sql/profiles/__init__.py +45 -0
  131. factlang-0.1.0/src/factlang/sql/profiles/_shared.py +67 -0
  132. factlang-0.1.0/src/factlang/sql/profiles/bigquery.py +104 -0
  133. factlang-0.1.0/src/factlang/sql/profiles/clickhouse.py +145 -0
  134. factlang-0.1.0/src/factlang/sql/profiles/databricks.py +94 -0
  135. factlang-0.1.0/src/factlang/sql/profiles/duckdb.py +93 -0
  136. factlang-0.1.0/src/factlang/sql/profiles/mysql.py +132 -0
  137. factlang-0.1.0/src/factlang/sql/profiles/oracle.py +114 -0
  138. factlang-0.1.0/src/factlang/sql/profiles/postgres.py +88 -0
  139. factlang-0.1.0/src/factlang/sql/profiles/redshift.py +102 -0
  140. factlang-0.1.0/src/factlang/sql/profiles/snowflake.py +98 -0
  141. factlang-0.1.0/src/factlang/sql/profiles/trino.py +90 -0
  142. factlang-0.1.0/src/factlang/sql/profiles/tsql.py +126 -0
  143. factlang-0.1.0/src/factlang/sql/registry.py +233 -0
  144. factlang-0.1.0/src/factlang/sql/sqlglot_bridge.py +763 -0
  145. factlang-0.1.0/src/factlang/syntax/__init__.py +6 -0
  146. factlang-0.1.0/src/factlang/syntax/ast.py +163 -0
  147. factlang-0.1.0/src/factlang/syntax/formatter.py +181 -0
  148. factlang-0.1.0/src/factlang/syntax/lexer.py +205 -0
  149. factlang-0.1.0/src/factlang/syntax/parser.py +542 -0
  150. factlang-0.1.0/src/factlang/syntax/tokens.py +45 -0
  151. factlang-0.1.0/src/factlang/types.py +41 -0
  152. factlang-0.1.0/tests/conformance/test_contract_completeness.py +245 -0
  153. factlang-0.1.0/tests/conformance/test_diagnostics_doc.py +93 -0
  154. factlang-0.1.0/tests/conformance/test_dialects.py +407 -0
  155. factlang-0.1.0/tests/conformance/test_docs_examples.py +178 -0
  156. factlang-0.1.0/tests/conformance/test_grammar_doc.py +76 -0
  157. factlang-0.1.0/tests/conformance/test_wiki_examples.py +91 -0
  158. factlang-0.1.0/tests/conformance/test_wiki_links.py +220 -0
  159. factlang-0.1.0/tests/fixtures/type_names/bigquery.json +24 -0
  160. factlang-0.1.0/tests/fixtures/type_names/clickhouse.json +31 -0
  161. factlang-0.1.0/tests/fixtures/type_names/databricks.json +23 -0
  162. factlang-0.1.0/tests/fixtures/type_names/duckdb.json +29 -0
  163. factlang-0.1.0/tests/fixtures/type_names/mysql.json +31 -0
  164. factlang-0.1.0/tests/fixtures/type_names/oracle.json +27 -0
  165. factlang-0.1.0/tests/fixtures/type_names/postgres.json +28 -0
  166. factlang-0.1.0/tests/fixtures/type_names/redshift.json +23 -0
  167. factlang-0.1.0/tests/fixtures/type_names/snowflake.json +25 -0
  168. factlang-0.1.0/tests/fixtures/type_names/trino.json +26 -0
  169. factlang-0.1.0/tests/fixtures/type_names/tsql.json +30 -0
  170. factlang-0.1.0/tests/integration/conftest.py +18 -0
  171. factlang-0.1.0/tests/integration/engines.py +292 -0
  172. factlang-0.1.0/tests/integration/expectations.py +375 -0
  173. factlang-0.1.0/tests/integration/shop.py +184 -0
  174. factlang-0.1.0/tests/integration/test_amendment_a.py +1072 -0
  175. factlang-0.1.0/tests/integration/test_verbs_duckdb.py +527 -0
  176. factlang-0.1.0/tests/integration/test_verbs_engines.py +323 -0
  177. factlang-0.1.0/tests/live/conftest.py +20 -0
  178. factlang-0.1.0/tests/live/live_targets.py +75 -0
  179. factlang-0.1.0/tests/live/test_live_smoke.py +50 -0
  180. factlang-0.1.0/tests/property/test_lexer_props.py +28 -0
  181. factlang-0.1.0/tests/property/test_parser_props.py +221 -0
  182. factlang-0.1.0/tests/test_architecture.py +338 -0
  183. factlang-0.1.0/tests/test_version.py +6 -0
  184. factlang-0.1.0/tests/unit/agent/test_mcp.py +297 -0
  185. factlang-0.1.0/tests/unit/agent/test_reference.py +149 -0
  186. factlang-0.1.0/tests/unit/agent/test_tools.py +254 -0
  187. factlang-0.1.0/tests/unit/connectors/test_base.py +668 -0
  188. factlang-0.1.0/tests/unit/connectors/test_bigquery_fake.py +259 -0
  189. factlang-0.1.0/tests/unit/connectors/test_callable.py +135 -0
  190. factlang-0.1.0/tests/unit/connectors/test_catalog_duckdb.py +236 -0
  191. factlang-0.1.0/tests/unit/connectors/test_dbapi_duckdb.py +381 -0
  192. factlang-0.1.0/tests/unit/connectors/test_dbapi_threads.py +209 -0
  193. factlang-0.1.0/tests/unit/connectors/test_sqlalchemy_fake.py +269 -0
  194. factlang-0.1.0/tests/unit/ir/test_primitives.py +385 -0
  195. factlang-0.1.0/tests/unit/judge/test_judge.py +178 -0
  196. factlang-0.1.0/tests/unit/judge/test_predicate.py +374 -0
  197. factlang-0.1.0/tests/unit/packs/packs_helpers.py +40 -0
  198. factlang-0.1.0/tests/unit/packs/test_answer_verbs.py +313 -0
  199. factlang-0.1.0/tests/unit/packs/test_dead.py +48 -0
  200. factlang-0.1.0/tests/unit/packs/test_exists.py +53 -0
  201. factlang-0.1.0/tests/unit/packs/test_fanout.py +62 -0
  202. factlang-0.1.0/tests/unit/packs/test_fresh.py +92 -0
  203. factlang-0.1.0/tests/unit/packs/test_join.py +215 -0
  204. factlang-0.1.0/tests/unit/packs/test_note.py +41 -0
  205. factlang-0.1.0/tests/unit/packs/test_nulls.py +67 -0
  206. factlang-0.1.0/tests/unit/packs/test_pattern.py +49 -0
  207. factlang-0.1.0/tests/unit/packs/test_range.py +141 -0
  208. factlang-0.1.0/tests/unit/packs/test_rows.py +56 -0
  209. factlang-0.1.0/tests/unit/packs/test_standard_pack.py +53 -0
  210. factlang-0.1.0/tests/unit/packs/test_type.py +62 -0
  211. factlang-0.1.0/tests/unit/packs/test_unique.py +61 -0
  212. factlang-0.1.0/tests/unit/packs/test_values.py +120 -0
  213. factlang-0.1.0/tests/unit/semantics/test_analyzer.py +684 -0
  214. factlang-0.1.0/tests/unit/semantics/test_catalog.py +184 -0
  215. factlang-0.1.0/tests/unit/semantics/test_checked.py +187 -0
  216. factlang-0.1.0/tests/unit/semantics/test_identity.py +203 -0
  217. factlang-0.1.0/tests/unit/semantics/test_signature.py +145 -0
  218. factlang-0.1.0/tests/unit/semantics/test_types.py +290 -0
  219. factlang-0.1.0/tests/unit/sql/test_duckdb_exec.py +342 -0
  220. factlang-0.1.0/tests/unit/sql/test_lower.py +836 -0
  221. factlang-0.1.0/tests/unit/sql/test_lowering_duckdb.py +266 -0
  222. factlang-0.1.0/tests/unit/sql/test_native_profiles.py +591 -0
  223. factlang-0.1.0/tests/unit/sql/test_printer.py +524 -0
  224. factlang-0.1.0/tests/unit/sql/test_probe.py +134 -0
  225. factlang-0.1.0/tests/unit/sql/test_sqlglot_bridge.py +691 -0
  226. factlang-0.1.0/tests/unit/syntax/test_diagnostics.py +45 -0
  227. factlang-0.1.0/tests/unit/syntax/test_formatter.py +109 -0
  228. factlang-0.1.0/tests/unit/syntax/test_lexer.py +217 -0
  229. factlang-0.1.0/tests/unit/syntax/test_parser.py +467 -0
  230. factlang-0.1.0/tests/unit/test_api.py +439 -0
  231. factlang-0.1.0/tests/unit/test_cli.py +558 -0
  232. factlang-0.1.0/tests/unit/test_contract.py +618 -0
  233. factlang-0.1.0/tests/unit/test_engine.py +499 -0
  234. factlang-0.1.0/tests/unit/test_optimizer.py +150 -0
@@ -0,0 +1,18 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .venv/
5
+ venv/
6
+ dist/
7
+ build/
8
+ site/
9
+ .superpowers/
10
+ .pytest_cache/
11
+ .mypy_cache/
12
+ .ruff_cache/
13
+ .hypothesis/
14
+ .coverage
15
+ .coverage.*
16
+ htmlcov/
17
+ coverage.xml
18
+ .DS_Store
@@ -0,0 +1,68 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
+ [Semantic Versioning](https://semver.org/). The language has its own version
6
+ (`LANGUAGE_VERSION`), independent of the package version.
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-11-24
11
+
12
+ The first release. Development status: Alpha. Python 3.10–3.13.
13
+
14
+ ### Added
15
+ - **The language, version 1.0** (`fl.LANGUAGE_VERSION`): line-oriented claims with typed
16
+ literals, `WHERE` filters (including bare boolean atoms), `USE` directives, canonical
17
+ formatting and a semantic hash; stable `FLnnn` diagnostics with carets and did-you-mean
18
+ suggestions. The grammar reference is normative and executed by the test suite.
19
+ - **19 standard verbs** in the `standard` pack 1.0: `EXISTS`, `TYPE`, `ROWS`, `COUNT`,
20
+ `NULLS`, `DEAD`, `UNIQUE`, `FANOUT`, `VALUES`, `RANGE`, `PATTERN`, `FRESH`, `JOIN`,
21
+ `DISTINCT`, `SUM`, `AVG`, `MIN`, `MAX`, `NOTE`. Contracts and packs are extensible
22
+ (register, override, alias, remove, extend, merge, the decorator API, `fl.check_pack`,
23
+ entry-point discovery with `fl.discover_packs`).
24
+ - **11 native dialects** rendered by the stdlib-only core: `duckdb`, `postgres`, `mysql`,
25
+ `clickhouse`, `tsql`, `trino` (tier `verified`, executed in CI) and `bigquery`,
26
+ `snowflake`, `redshift`, `databricks`, `oracle` (tier `native`); any other dialect
27
+ sqlglot can write through the optional sqlglot bridge (tier `best_effort`).
28
+ - **Connectors**: `DBAPIConnector` (any PEP 249 connection), `CallableConnector`,
29
+ `SQLAlchemyConnector`, `BigQueryConnector`, `fl.connect`; catalogs (`StaticCatalog`,
30
+ `NullCatalog`, `CachedCatalog`, `WarehouseCatalog`) and the `Catalog` protocol.
31
+ - **Engine**: `Checker.check` / `acheck` with probe fusion and batching; every outcome
32
+ carries facts and evidence (SQL, typed bind parameters, dialect, tier, timings);
33
+ `Report.verified` (every measurable claim was measured and passed, stricter than `ok`).
34
+ `Checker.measure` / `ameasure` and `Checker.estimate` (cost without executing).
35
+ - **Command line** `factlang`: `lint`, `fmt`, `explain`, `check` (`--dsn`, `--connector`,
36
+ `FACTLANG_DSN`), `verbs`, `mcp`; text, JSON and Markdown output; exit codes 0/1/2/3.
37
+ - **Agent tools**: `factlang_check`, `factlang_lint`, `factlang_explain` tool definitions,
38
+ a dispatcher and verb references for prompts; the same tools served over MCP on stdio
39
+ (`factlang mcp`, extra `mcp`).
40
+ - **Amendment A** (requirements of a dependent schema profiler): raw measurement of IR
41
+ primitives without a claim (`fl.measure`, `Measurement`); exact top-k observed values
42
+ (`VALUES … IN []`); composite join keys (`JOIN … WITH [..] TO [..]`); reverse and row
43
+ join facts (`coverage`, `row_match_rate`, `fan_in`, …, `COVERAGE`); cost estimates
44
+ (`CostEstimate`); public `fl.parse_filter`, `fl.sql.render_filter`, `fl.sql.render_join`,
45
+ `RenderedFragment`; the native `trino` profile; guarded metadata SQL
46
+ (`fl.connectors.run_metadata`, `FL703`); bare boolean filter atoms.
47
+ - **Amendment B**: sampled raw measurement for very large tables. `SampleSpec`
48
+ (`keyhash`, `system`, `bernoulli`; deterministic seeds) on IR primitives, rendered per
49
+ dialect, used **only** by `Checker.measure`. No verdict is ever produced from sampled
50
+ data: a sampled plan in a claim is `FL404`, `FL405` and `FL506` guard the methods.
51
+ - **Stable public API** (R10): `fl.__all__` and the table in the
52
+ [API reference](https://rupakc.github.io/factlang/reference/api/) follow SemVer, with no
53
+ breaking change within a `0.x` minor series. Includes `fl.Ident`, `fl.TableRef`,
54
+ `fl.ColumnRef`, `fl.EdgeRef`, `fl.check_pack`, `fl.discover_packs`, `fl.Catalog`,
55
+ `fl.types.LiteralKind` (also `from factlang.types import LiteralKind`), `fl.sql.Param`,
56
+ `factlang.syntax.FILTER_KEYWORDS`.
57
+ - `factlang mcp` reads `FACTLANG_DSN` when neither `--dsn` nor `--dialect` is given.
58
+ - Documentation site with an in-browser playground, GitHub wiki, CI on Python 3.10–3.13
59
+ with service-container integration tests, and a tag-triggered release workflow
60
+ (PyPI Trusted Publishing and a GitHub Release with the sdist and wheel).
61
+
62
+ ### Fixed
63
+ - A quoted and a bare spelling of one table in the same document no longer fuse into one
64
+ probe (both claims were reported as `FL500`).
65
+ - `str(Verdict.PASS)` is `"pass"`.
66
+
67
+ [Unreleased]: https://github.com/rupakc/factlang/compare/v0.1.0...HEAD
68
+ [0.1.0]: https://github.com/rupakc/factlang/releases/tag/v0.1.0
factlang-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rupak Chakraborty
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,283 @@
1
+ Metadata-Version: 2.5
2
+ Name: factlang
3
+ Version: 0.1.0
4
+ Summary: A formal language for verifying factual claims against data warehouses.
5
+ Project-URL: Homepage, https://github.com/rupakc/factlang
6
+ Project-URL: Documentation, https://rupakc.github.io/factlang/
7
+ Project-URL: Source, https://github.com/rupakc/factlang
8
+ Project-URL: Issues, https://github.com/rupakc/factlang/issues
9
+ Project-URL: Changelog, https://github.com/rupakc/factlang/blob/main/CHANGELOG.md
10
+ Author: Rupak Chakraborty
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: claims,data-quality,data-warehouse,fact-checking,llm-agents,sql
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Environment :: Console
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
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 :: Database
24
+ Classifier: Topic :: Software Development :: Quality Assurance
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.10
27
+ Provides-Extra: all
28
+ Requires-Dist: clickhouse-connect>=0.7; extra == 'all'
29
+ Requires-Dist: databricks-sql-connector>=3; extra == 'all'
30
+ Requires-Dist: duckdb>=1.0; extra == 'all'
31
+ Requires-Dist: google-cloud-bigquery>=3; extra == 'all'
32
+ Requires-Dist: mcp<3,>=1.0; extra == 'all'
33
+ Requires-Dist: oracledb>=2; extra == 'all'
34
+ Requires-Dist: psycopg[binary]>=3.1; extra == 'all'
35
+ Requires-Dist: pymysql>=1.1; extra == 'all'
36
+ Requires-Dist: pyodbc>=5; extra == 'all'
37
+ Requires-Dist: redshift-connector>=2; extra == 'all'
38
+ Requires-Dist: snowflake-connector-python>=3; extra == 'all'
39
+ Requires-Dist: sqlalchemy>=2; extra == 'all'
40
+ Requires-Dist: sqlglot<31,>=30; extra == 'all'
41
+ Requires-Dist: trino>=0.330; extra == 'all'
42
+ Provides-Extra: bigquery
43
+ Requires-Dist: google-cloud-bigquery>=3; extra == 'bigquery'
44
+ Provides-Extra: clickhouse
45
+ Requires-Dist: clickhouse-connect>=0.7; extra == 'clickhouse'
46
+ Provides-Extra: databricks
47
+ Requires-Dist: databricks-sql-connector>=3; extra == 'databricks'
48
+ Provides-Extra: dev
49
+ Requires-Dist: build; extra == 'dev'
50
+ Requires-Dist: duckdb>=1.0; extra == 'dev'
51
+ Requires-Dist: hypothesis>=6; extra == 'dev'
52
+ Requires-Dist: mypy; extra == 'dev'
53
+ Requires-Dist: pytest-cov; extra == 'dev'
54
+ Requires-Dist: pytest>=8; extra == 'dev'
55
+ Requires-Dist: ruff; extra == 'dev'
56
+ Requires-Dist: sqlglot<31,>=30; extra == 'dev'
57
+ Requires-Dist: twine; extra == 'dev'
58
+ Provides-Extra: docs
59
+ Requires-Dist: mkdocs-material<10,>=9.5; extra == 'docs'
60
+ Requires-Dist: mkdocs<2,>=1.6; extra == 'docs'
61
+ Requires-Dist: mkdocstrings[python]<2,>=0.26; extra == 'docs'
62
+ Provides-Extra: duckdb
63
+ Requires-Dist: duckdb>=1.0; extra == 'duckdb'
64
+ Provides-Extra: mcp
65
+ Requires-Dist: mcp<3,>=1.0; extra == 'mcp'
66
+ Provides-Extra: mssql
67
+ Requires-Dist: pyodbc>=5; extra == 'mssql'
68
+ Provides-Extra: mysql
69
+ Requires-Dist: pymysql>=1.1; extra == 'mysql'
70
+ Provides-Extra: oracle
71
+ Requires-Dist: oracledb>=2; extra == 'oracle'
72
+ Provides-Extra: postgres
73
+ Requires-Dist: psycopg[binary]>=3.1; extra == 'postgres'
74
+ Provides-Extra: redshift
75
+ Requires-Dist: redshift-connector>=2; extra == 'redshift'
76
+ Provides-Extra: snowflake
77
+ Requires-Dist: snowflake-connector-python>=3; extra == 'snowflake'
78
+ Provides-Extra: sqlalchemy
79
+ Requires-Dist: sqlalchemy>=2; extra == 'sqlalchemy'
80
+ Provides-Extra: sqlglot
81
+ Requires-Dist: sqlglot<31,>=30; extra == 'sqlglot'
82
+ Provides-Extra: trino
83
+ Requires-Dist: trino>=0.330; extra == 'trino'
84
+ Description-Content-Type: text/markdown
85
+
86
+ # FactLang
87
+
88
+ [![CI](https://github.com/rupakc/factlang/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/rupakc/factlang/actions/workflows/ci.yml)
89
+ [![PyPI](https://img.shields.io/pypi/v/factlang.svg)](https://pypi.org/project/factlang/)
90
+ [![Python versions](https://img.shields.io/pypi/pyversions/factlang.svg)](https://pypi.org/project/factlang/)
91
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/rupakc/factlang/blob/main/LICENSE)
92
+ [![Docs](https://img.shields.io/badge/docs-rupakc.github.io%2Ffactlang-informational.svg)](https://rupakc.github.io/factlang/)
93
+
94
+ FactLang is a small formal language for verifying factual claims against data warehouses.
95
+ You write a claim such as "the `orders` table has at least 1,000 rows" or "every
96
+ `order_items.order_id` exists in `orders.id`". FactLang checks it statically, compiles it to
97
+ read-only SQL for your dialect, runs it over **all** the data, and returns a verdict
98
+ (`pass`, `fail`, `no_data`, `error`, …) with the numbers and the SQL behind it.
99
+
100
+ Why: numbers in LLM answers, schema registries, data contracts and migration plans are
101
+ claims about data, and claims drift. FactLang makes them checkable, line by line, with
102
+ evidence a human can audit. The core is pure standard-library Python with no dependencies.
103
+
104
+ **Status: Alpha (0.1.0).** Python 3.10–3.13. Language version `1.0`.
105
+ [Documentation](https://rupakc.github.io/factlang/) ·
106
+ [Wiki](https://github.com/rupakc/factlang/wiki) ·
107
+ [Changelog](https://github.com/rupakc/factlang/blob/main/CHANGELOG.md)
108
+
109
+ ## Thirty seconds
110
+
111
+ ```bash
112
+ pip install "factlang[duckdb]"
113
+ ```
114
+
115
+ ```python
116
+ import duckdb
117
+ import factlang as fl
118
+
119
+ conn = duckdb.connect()
120
+ conn.execute("""
121
+ CREATE TABLE orders AS
122
+ SELECT i AS id,
123
+ CASE WHEN i % 10 = 0 THEN 'refunded' ELSE 'paid' END AS status
124
+ FROM range(1, 1001) AS t(i)
125
+ """)
126
+
127
+ claims = """
128
+ ROWS orders VALUE >=1000
129
+ UNIQUE orders.id
130
+ VALUES orders.status IN ['paid', 'open']
131
+ """
132
+ report = fl.Checker(fl.DBAPIConnector(conn, "duckdb")).check(claims)
133
+
134
+ for o in report.outcomes:
135
+ print(f"{o.verdict.value:5} {o.claim_text:42} {o.explanation}")
136
+ print("verified:", report.verified)
137
+
138
+ assert [o.verdict.value for o in report.outcomes] == ["pass", "pass", "fail"]
139
+ assert not report.verified
140
+ ```
141
+
142
+ ```text
143
+ pass ROWS orders VALUE >=1000 row_count 1000 >= 1000
144
+ pass UNIQUE orders.id max_rows_per_key 1 <= 1
145
+ fail VALUES orders.status IN ['paid', 'open'] undeclared_rows 100 != 0
146
+ verified: False
147
+ ```
148
+
149
+ `report.verified` is the flag to gate on: every measurable claim was measured and passed.
150
+ Each outcome also carries `facts` (every number the verb measured) and `evidence` (the SQL,
151
+ its bind parameters, the dialect and its tier). The
152
+ [getting-started guide](https://rupakc.github.io/factlang/getting-started/) goes further.
153
+
154
+ ## Install
155
+
156
+ ```bash
157
+ pip install factlang # the core: no dependencies at all
158
+ pip install "factlang[postgres]" # plus a driver for your warehouse
159
+ ```
160
+
161
+ | extra | adds | for |
162
+ |---|---|---|
163
+ | `duckdb` | `duckdb` | DuckDB |
164
+ | `postgres` | `psycopg[binary]` | PostgreSQL |
165
+ | `mysql` | `pymysql` | MySQL |
166
+ | `clickhouse` | `clickhouse-connect` | ClickHouse |
167
+ | `mssql` | `pyodbc` | SQL Server (`tsql`) |
168
+ | `trino` | `trino` | Trino |
169
+ | `bigquery` | `google-cloud-bigquery` | BigQuery |
170
+ | `snowflake` | `snowflake-connector-python` | Snowflake |
171
+ | `redshift` | `redshift-connector` | Redshift |
172
+ | `databricks` | `databricks-sql-connector` | Databricks |
173
+ | `oracle` | `oracledb` | Oracle |
174
+ | `sqlalchemy` | `sqlalchemy` | any SQLAlchemy URL (`--dsn`, `FACTLANG_DSN`) |
175
+ | `sqlglot` | `sqlglot` | the long tail of dialects (tier `best_effort`) |
176
+ | `mcp` | `mcp` | the MCP server (`factlang mcp`) |
177
+ | `all` | every one of the above | |
178
+
179
+ Any PEP 249 connection works through `fl.DBAPIConnector(conn, "<dialect>")`; the extras only
180
+ install drivers.
181
+
182
+ ## The standard verbs
183
+
184
+ Nineteen verbs, one claim per line. The
185
+ [verb reference](https://rupakc.github.io/factlang/reference/verbs/) lists every attribute.
186
+
187
+ | verb | example | passes when |
188
+ |---|---|---|
189
+ | `EXISTS` | `EXISTS orders COLUMN shipped_at` | the table (or column) exists in the catalog |
190
+ | `TYPE` | `TYPE orders.amount IS decimal` | the column's type family equals the stated one |
191
+ | `ROWS` | `ROWS orders VALUE >=1000` | the row count satisfies the comparison |
192
+ | `COUNT` | `COUNT orders VALUE ==1400 WHERE status = 'paid'` | the (filtered) row count satisfies the comparison |
193
+ | `NULLS` | `NULLS orders.shipped_at RATE <=5%` | the NULL share satisfies the comparison |
194
+ | `DEAD` | `DEAD orders.legacy_flag` | every value is NULL |
195
+ | `UNIQUE` | `UNIQUE order_items.order_id WITH [line_no]` | no (composite) key is held by more than one row |
196
+ | `FANOUT` | `FANOUT order_items.order_id MAX_PER_KEY <=50` | the busiest key's row count satisfies the comparison |
197
+ | `VALUES` | `VALUES orders.status IN ['paid', 'open']` | every non-NULL value is declared |
198
+ | `RANGE` | `RANGE orders.amount BETWEEN [0, 10000]` | min and max lie inside the closed range |
199
+ | `PATTERN` | `PATTERN customers.email LIKE '%@%.%' RATE >=99%` | the share matching the pattern satisfies the comparison |
200
+ | `FRESH` | `FRESH events.created_at WITHIN 24h` | the newest value is no older than the duration |
201
+ | `JOIN` | `JOIN orders.customer_id -> customers.id CARD N:1 MATCH >=99%` | the share of left keys that find a right key satisfies the comparison |
202
+ | `DISTINCT` | `DISTINCT orders.customer_id VALUE ==512` | the distinct non-NULL count satisfies the comparison |
203
+ | `SUM` | `SUM orders.amount VALUE ==209000 TOLERANCE 1%` | the sum satisfies the comparison |
204
+ | `AVG` | `AVG orders.amount VALUE ==104.5 ABS_TOLERANCE 0.01` | the average satisfies the comparison |
205
+ | `MIN` | `MIN orders.amount VALUE >=0` | the smallest value satisfies the comparison |
206
+ | `MAX` | `MAX orders.placed_on VALUE <=DATE '2026-12-31'` | the largest value satisfies the comparison |
207
+ | `NOTE` | `NOTE orders.amount IS eur BECAUSE 'all prices are stored in euro'` | never measured: a recorded semantic fact |
208
+
209
+ Every verb accepts a `WHERE` filter where it makes sense. You can add, override, alias or
210
+ remove verbs in your own [pack](https://rupakc.github.io/factlang/extending/packs/).
211
+
212
+ ## Dialects
213
+
214
+ Eleven dialects are rendered natively by the pure-Python core; every outcome reports the
215
+ **tier** of the SQL that produced it.
216
+
217
+ | tier | dialects | what it means |
218
+ |---|---|---|
219
+ | `verified` | `duckdb`, `postgres`, `mysql`, `clickhouse`, `tsql`, `trino` | the native SQL runs against a real engine in CI, verb by verb |
220
+ | `native` | `bigquery`, `snowflake`, `redshift`, `databricks`, `oracle` | native SQL checked by parsing it with sqlglot in that dialect and by golden tests; an opt-in live suite runs it when credentials are present |
221
+ | `best_effort` | any other dialect sqlglot can write (`presto`, `athena`, `hive`, `teradata`, …) | rendered through the optional sqlglot bridge (`pip install "factlang[sqlglot]"`) |
222
+
223
+ ## Command line
224
+
225
+ ```bash
226
+ factlang lint facts.fl # diagnostics only; never executes
227
+ factlang fmt --check facts.fl # canonical formatting, for CI
228
+ factlang explain --dialect bigquery facts.fl # print each claim's SQL
229
+ export FACTLANG_DSN="postgresql+psycopg://reader@warehouse/shop"
230
+ factlang check facts.fl # run the claims (needs factlang[sqlalchemy])
231
+ factlang check --format json facts.fl # also: --format markdown
232
+ factlang verbs # list the standard verbs
233
+ ```
234
+
235
+ | exit code | meaning |
236
+ |---|---|
237
+ | `0` | every claim passed (or is unprobeable) |
238
+ | `1` | a claim failed; for `fmt --check`, a file would be reformatted |
239
+ | `2` | invalid input: bad usage, an unreadable file, a claim with front-end errors, a connector that cannot be loaded |
240
+ | `3` | errors or undecidable: an `error` or `no_data` outcome, a claim that cannot be rendered |
241
+
242
+ When several apply, `2` wins over `1`, and `1` over `3`. See the
243
+ [CLI guide](https://rupakc.github.io/factlang/cli/).
244
+
245
+ ## Agents and MCP
246
+
247
+ FactLang ships tool definitions for LLM agents (`factlang_check`, `factlang_lint`,
248
+ `factlang_explain`) and serves the same tools over MCP on stdio:
249
+
250
+ ```bash
251
+ pip install "factlang[mcp,sqlalchemy]"
252
+ export FACTLANG_DSN="postgresql+psycopg://reader@warehouse/shop"
253
+ factlang mcp # register this as a stdio command in your MCP client
254
+ factlang mcp --dialect snowflake # no warehouse: lint and explain only
255
+ ```
256
+
257
+ Have the model emit claims alongside its answer and gate on `verified`. See
258
+ [Agents and LLMs](https://rupakc.github.io/factlang/agents/).
259
+
260
+ ## Guarantees
261
+
262
+ - **No sampling in claims.** Every verdict is computed over every row that matches the
263
+ claim's filter. Sampling exists only in `Checker.measure`, the raw-measurement API, when
264
+ you ask for it, and its evidence says so
265
+ ([details](https://rupakc.github.io/factlang/guide/measure/)).
266
+ - **Read-only SQL, typed parameters.** Probes are `SELECT`-only, claims cannot contain raw
267
+ SQL, and every literal travels as a typed bind parameter. Use a database role that can
268
+ only read: **your credentials are the security boundary.**
269
+ - **Undecidable stays undecidable.** A fact the data cannot support is `no_data`, never a
270
+ pass; a query the warehouse rejects is `error`.
271
+ - **Stable API.** The names in `fl.__all__` and the
272
+ [stable API table](https://rupakc.github.io/factlang/reference/api/) follow SemVer: no
273
+ breaking change within a `0.x` minor series.
274
+
275
+ ## Project
276
+
277
+ - [Documentation](https://rupakc.github.io/factlang/) and the in-browser
278
+ [playground](https://rupakc.github.io/factlang/playground/)
279
+ - [Wiki](https://github.com/rupakc/factlang/wiki): concepts, architecture, design decisions
280
+ - [Changelog](https://github.com/rupakc/factlang/blob/main/CHANGELOG.md)
281
+ - [Contributing](https://github.com/rupakc/factlang/blob/main/CONTRIBUTING.md)
282
+ - [Security policy](https://github.com/rupakc/factlang/blob/main/SECURITY.md)
283
+ - [License: MIT](https://github.com/rupakc/factlang/blob/main/LICENSE)
@@ -0,0 +1,198 @@
1
+ # FactLang
2
+
3
+ [![CI](https://github.com/rupakc/factlang/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/rupakc/factlang/actions/workflows/ci.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/factlang.svg)](https://pypi.org/project/factlang/)
5
+ [![Python versions](https://img.shields.io/pypi/pyversions/factlang.svg)](https://pypi.org/project/factlang/)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/rupakc/factlang/blob/main/LICENSE)
7
+ [![Docs](https://img.shields.io/badge/docs-rupakc.github.io%2Ffactlang-informational.svg)](https://rupakc.github.io/factlang/)
8
+
9
+ FactLang is a small formal language for verifying factual claims against data warehouses.
10
+ You write a claim such as "the `orders` table has at least 1,000 rows" or "every
11
+ `order_items.order_id` exists in `orders.id`". FactLang checks it statically, compiles it to
12
+ read-only SQL for your dialect, runs it over **all** the data, and returns a verdict
13
+ (`pass`, `fail`, `no_data`, `error`, …) with the numbers and the SQL behind it.
14
+
15
+ Why: numbers in LLM answers, schema registries, data contracts and migration plans are
16
+ claims about data, and claims drift. FactLang makes them checkable, line by line, with
17
+ evidence a human can audit. The core is pure standard-library Python with no dependencies.
18
+
19
+ **Status: Alpha (0.1.0).** Python 3.10–3.13. Language version `1.0`.
20
+ [Documentation](https://rupakc.github.io/factlang/) ·
21
+ [Wiki](https://github.com/rupakc/factlang/wiki) ·
22
+ [Changelog](https://github.com/rupakc/factlang/blob/main/CHANGELOG.md)
23
+
24
+ ## Thirty seconds
25
+
26
+ ```bash
27
+ pip install "factlang[duckdb]"
28
+ ```
29
+
30
+ ```python
31
+ import duckdb
32
+ import factlang as fl
33
+
34
+ conn = duckdb.connect()
35
+ conn.execute("""
36
+ CREATE TABLE orders AS
37
+ SELECT i AS id,
38
+ CASE WHEN i % 10 = 0 THEN 'refunded' ELSE 'paid' END AS status
39
+ FROM range(1, 1001) AS t(i)
40
+ """)
41
+
42
+ claims = """
43
+ ROWS orders VALUE >=1000
44
+ UNIQUE orders.id
45
+ VALUES orders.status IN ['paid', 'open']
46
+ """
47
+ report = fl.Checker(fl.DBAPIConnector(conn, "duckdb")).check(claims)
48
+
49
+ for o in report.outcomes:
50
+ print(f"{o.verdict.value:5} {o.claim_text:42} {o.explanation}")
51
+ print("verified:", report.verified)
52
+
53
+ assert [o.verdict.value for o in report.outcomes] == ["pass", "pass", "fail"]
54
+ assert not report.verified
55
+ ```
56
+
57
+ ```text
58
+ pass ROWS orders VALUE >=1000 row_count 1000 >= 1000
59
+ pass UNIQUE orders.id max_rows_per_key 1 <= 1
60
+ fail VALUES orders.status IN ['paid', 'open'] undeclared_rows 100 != 0
61
+ verified: False
62
+ ```
63
+
64
+ `report.verified` is the flag to gate on: every measurable claim was measured and passed.
65
+ Each outcome also carries `facts` (every number the verb measured) and `evidence` (the SQL,
66
+ its bind parameters, the dialect and its tier). The
67
+ [getting-started guide](https://rupakc.github.io/factlang/getting-started/) goes further.
68
+
69
+ ## Install
70
+
71
+ ```bash
72
+ pip install factlang # the core: no dependencies at all
73
+ pip install "factlang[postgres]" # plus a driver for your warehouse
74
+ ```
75
+
76
+ | extra | adds | for |
77
+ |---|---|---|
78
+ | `duckdb` | `duckdb` | DuckDB |
79
+ | `postgres` | `psycopg[binary]` | PostgreSQL |
80
+ | `mysql` | `pymysql` | MySQL |
81
+ | `clickhouse` | `clickhouse-connect` | ClickHouse |
82
+ | `mssql` | `pyodbc` | SQL Server (`tsql`) |
83
+ | `trino` | `trino` | Trino |
84
+ | `bigquery` | `google-cloud-bigquery` | BigQuery |
85
+ | `snowflake` | `snowflake-connector-python` | Snowflake |
86
+ | `redshift` | `redshift-connector` | Redshift |
87
+ | `databricks` | `databricks-sql-connector` | Databricks |
88
+ | `oracle` | `oracledb` | Oracle |
89
+ | `sqlalchemy` | `sqlalchemy` | any SQLAlchemy URL (`--dsn`, `FACTLANG_DSN`) |
90
+ | `sqlglot` | `sqlglot` | the long tail of dialects (tier `best_effort`) |
91
+ | `mcp` | `mcp` | the MCP server (`factlang mcp`) |
92
+ | `all` | every one of the above | |
93
+
94
+ Any PEP 249 connection works through `fl.DBAPIConnector(conn, "<dialect>")`; the extras only
95
+ install drivers.
96
+
97
+ ## The standard verbs
98
+
99
+ Nineteen verbs, one claim per line. The
100
+ [verb reference](https://rupakc.github.io/factlang/reference/verbs/) lists every attribute.
101
+
102
+ | verb | example | passes when |
103
+ |---|---|---|
104
+ | `EXISTS` | `EXISTS orders COLUMN shipped_at` | the table (or column) exists in the catalog |
105
+ | `TYPE` | `TYPE orders.amount IS decimal` | the column's type family equals the stated one |
106
+ | `ROWS` | `ROWS orders VALUE >=1000` | the row count satisfies the comparison |
107
+ | `COUNT` | `COUNT orders VALUE ==1400 WHERE status = 'paid'` | the (filtered) row count satisfies the comparison |
108
+ | `NULLS` | `NULLS orders.shipped_at RATE <=5%` | the NULL share satisfies the comparison |
109
+ | `DEAD` | `DEAD orders.legacy_flag` | every value is NULL |
110
+ | `UNIQUE` | `UNIQUE order_items.order_id WITH [line_no]` | no (composite) key is held by more than one row |
111
+ | `FANOUT` | `FANOUT order_items.order_id MAX_PER_KEY <=50` | the busiest key's row count satisfies the comparison |
112
+ | `VALUES` | `VALUES orders.status IN ['paid', 'open']` | every non-NULL value is declared |
113
+ | `RANGE` | `RANGE orders.amount BETWEEN [0, 10000]` | min and max lie inside the closed range |
114
+ | `PATTERN` | `PATTERN customers.email LIKE '%@%.%' RATE >=99%` | the share matching the pattern satisfies the comparison |
115
+ | `FRESH` | `FRESH events.created_at WITHIN 24h` | the newest value is no older than the duration |
116
+ | `JOIN` | `JOIN orders.customer_id -> customers.id CARD N:1 MATCH >=99%` | the share of left keys that find a right key satisfies the comparison |
117
+ | `DISTINCT` | `DISTINCT orders.customer_id VALUE ==512` | the distinct non-NULL count satisfies the comparison |
118
+ | `SUM` | `SUM orders.amount VALUE ==209000 TOLERANCE 1%` | the sum satisfies the comparison |
119
+ | `AVG` | `AVG orders.amount VALUE ==104.5 ABS_TOLERANCE 0.01` | the average satisfies the comparison |
120
+ | `MIN` | `MIN orders.amount VALUE >=0` | the smallest value satisfies the comparison |
121
+ | `MAX` | `MAX orders.placed_on VALUE <=DATE '2026-12-31'` | the largest value satisfies the comparison |
122
+ | `NOTE` | `NOTE orders.amount IS eur BECAUSE 'all prices are stored in euro'` | never measured: a recorded semantic fact |
123
+
124
+ Every verb accepts a `WHERE` filter where it makes sense. You can add, override, alias or
125
+ remove verbs in your own [pack](https://rupakc.github.io/factlang/extending/packs/).
126
+
127
+ ## Dialects
128
+
129
+ Eleven dialects are rendered natively by the pure-Python core; every outcome reports the
130
+ **tier** of the SQL that produced it.
131
+
132
+ | tier | dialects | what it means |
133
+ |---|---|---|
134
+ | `verified` | `duckdb`, `postgres`, `mysql`, `clickhouse`, `tsql`, `trino` | the native SQL runs against a real engine in CI, verb by verb |
135
+ | `native` | `bigquery`, `snowflake`, `redshift`, `databricks`, `oracle` | native SQL checked by parsing it with sqlglot in that dialect and by golden tests; an opt-in live suite runs it when credentials are present |
136
+ | `best_effort` | any other dialect sqlglot can write (`presto`, `athena`, `hive`, `teradata`, …) | rendered through the optional sqlglot bridge (`pip install "factlang[sqlglot]"`) |
137
+
138
+ ## Command line
139
+
140
+ ```bash
141
+ factlang lint facts.fl # diagnostics only; never executes
142
+ factlang fmt --check facts.fl # canonical formatting, for CI
143
+ factlang explain --dialect bigquery facts.fl # print each claim's SQL
144
+ export FACTLANG_DSN="postgresql+psycopg://reader@warehouse/shop"
145
+ factlang check facts.fl # run the claims (needs factlang[sqlalchemy])
146
+ factlang check --format json facts.fl # also: --format markdown
147
+ factlang verbs # list the standard verbs
148
+ ```
149
+
150
+ | exit code | meaning |
151
+ |---|---|
152
+ | `0` | every claim passed (or is unprobeable) |
153
+ | `1` | a claim failed; for `fmt --check`, a file would be reformatted |
154
+ | `2` | invalid input: bad usage, an unreadable file, a claim with front-end errors, a connector that cannot be loaded |
155
+ | `3` | errors or undecidable: an `error` or `no_data` outcome, a claim that cannot be rendered |
156
+
157
+ When several apply, `2` wins over `1`, and `1` over `3`. See the
158
+ [CLI guide](https://rupakc.github.io/factlang/cli/).
159
+
160
+ ## Agents and MCP
161
+
162
+ FactLang ships tool definitions for LLM agents (`factlang_check`, `factlang_lint`,
163
+ `factlang_explain`) and serves the same tools over MCP on stdio:
164
+
165
+ ```bash
166
+ pip install "factlang[mcp,sqlalchemy]"
167
+ export FACTLANG_DSN="postgresql+psycopg://reader@warehouse/shop"
168
+ factlang mcp # register this as a stdio command in your MCP client
169
+ factlang mcp --dialect snowflake # no warehouse: lint and explain only
170
+ ```
171
+
172
+ Have the model emit claims alongside its answer and gate on `verified`. See
173
+ [Agents and LLMs](https://rupakc.github.io/factlang/agents/).
174
+
175
+ ## Guarantees
176
+
177
+ - **No sampling in claims.** Every verdict is computed over every row that matches the
178
+ claim's filter. Sampling exists only in `Checker.measure`, the raw-measurement API, when
179
+ you ask for it, and its evidence says so
180
+ ([details](https://rupakc.github.io/factlang/guide/measure/)).
181
+ - **Read-only SQL, typed parameters.** Probes are `SELECT`-only, claims cannot contain raw
182
+ SQL, and every literal travels as a typed bind parameter. Use a database role that can
183
+ only read: **your credentials are the security boundary.**
184
+ - **Undecidable stays undecidable.** A fact the data cannot support is `no_data`, never a
185
+ pass; a query the warehouse rejects is `error`.
186
+ - **Stable API.** The names in `fl.__all__` and the
187
+ [stable API table](https://rupakc.github.io/factlang/reference/api/) follow SemVer: no
188
+ breaking change within a `0.x` minor series.
189
+
190
+ ## Project
191
+
192
+ - [Documentation](https://rupakc.github.io/factlang/) and the in-browser
193
+ [playground](https://rupakc.github.io/factlang/playground/)
194
+ - [Wiki](https://github.com/rupakc/factlang/wiki): concepts, architecture, design decisions
195
+ - [Changelog](https://github.com/rupakc/factlang/blob/main/CHANGELOG.md)
196
+ - [Contributing](https://github.com/rupakc/factlang/blob/main/CONTRIBUTING.md)
197
+ - [Security policy](https://github.com/rupakc/factlang/blob/main/SECURITY.md)
198
+ - [License: MIT](https://github.com/rupakc/factlang/blob/main/LICENSE)