Ingesting data¶
The source of every fact is decided by how it reaches the ledger: which mapping, which folder, which connector. It is never decided by what the data says about itself.
Structured exports: CSV mappings (no LLM)¶
# hubspot_deals.yaml
source: hubspot_crm # fixed here, never read from the data
subject: "customer:{company_id}"
observed_at: "{updated_at}"
effective_from: "{updated_at}"
source_ref: "hubspot deal {deal_id}"
assertions:
- predicate: "price.{plan}.monthly_inr" # "Enterprise" becomes "enterprise"
value: "{amount}"
type: int # "₹99,000" becomes 99000
aliases:
- {alias: "{company_name}", kind: name}
ledger.import_csv("hubspot_deals.csv", "hubspot_deals.yaml")
The import is all-or-nothing: every row is validated first, and any error lists the row numbers before anything is written. Value types are str, int, float, bool and json.
Documents and messages: LLM extraction with verification¶
from assertion_ledger import Document, Extractor, Vocabulary
from assertion_ledger.llm.gemini import GeminiLLM # pip install "assertion-ledger[gemini]"
extractor = Extractor(GeminiLLM(), Vocabulary.load("template:b2b_saas_pricing"))
doc = Document(text=open("contract.md").read(), source="signed_contracts",
observed_at="2026-08-28", source_ref="contract #928")
result = ledger.ingest_document(doc, extractor)
result.assertions, result.retractions, result.rejected, result.warnings
The LLM proposes facts as structured JSON. verify() is deterministic and keeps a fact only if every check passes:
| Check | Rejection code |
|---|---|
| The quote is in the document (whitespace and typographic punctuation are tolerated, as is a garbled symbol right before a number) | quote_not_found |
| The value is written in the quote. "₹1,14,000", "114k" and "1.14 lakh" all count; a value computed from the text doesn't | value_not_in_quote, bad_value |
| The quote isn't in another currency than the predicate's | currency_mismatch |
| The predicate is in the vocabulary | unknown_predicate |
| The predicate fits the subject's type (a customer price can't attach to a product) | predicate_not_for_subject_type |
| The document names what the predicate is specific to (e.g. the plan) | predicate_not_grounded |
| The subject links to exactly one registered name or alias | unknown_subject, ambiguous_subject, subject_mismatch |
| Dates are written in the document, or equal the document date | ungrounded_date, bad_date, bad_interval |
| A withdrawal quote contains the reference and withdrawal wording | ref_not_in_quote, ref_names_no_identifier, no_withdrawal_cue |
| A withdrawal targets a known record, from a source of at least its tier | ref_unmatched, ref_ambiguous, withdrawal_not_authorized |
Some details:
- No stated start date means "from when it was said".
- End dates: the model copies the end date as written and flags inclusive wording ("through 30 November"); code adds the day.
- Supersession ("replaces contract #935") links only through identifier tokens ("935") to a source_ref the ledger holds. Prose like "supersedes all previous contracts" links to nothing. An unmatched reference is dropped with a warning, but the fact is kept.
Facts get the document's source, and so its tier. A Slack message that calls itself "official" is still tier 10.
Vocabulary¶
predicates:
price.growth.monthly_inr:
description: Monthly price in INR that a customer pays for the Growth plan
currency: INR # a quote in USD is rejected
subject_types: [customer] # not for product: or policy: subjects
requires_any: [growth] # the document must say "growth"
contact.billing_email:
description: Email address of the customer's billing contact
type: text # money (default) | number | text
Any model¶
Extractor takes any object with model_id and generate(system=, user=, schema=) -> dict. GeminiLLM (with retries) ships as an extra. ScriptedLLM is for tests.
Graphiti¶
from assertion_ledger.integrations.graphiti import fetch_episodes, import_episodes
episodes = await fetch_episodes(graphiti_driver, ["acme_demo"])
report = import_episodes(ledger, extractor, episodes, source_map={
"Signed customer contract*": "signed_contracts",
"HubSpot CRM*": "hubspot_crm",
"Slack message*": "slack",
})
The importer reads Graphiti's episodes (raw text and provenance), not its edges. Edges are LLM paraphrases, and their invalidation is newest-wins. Episodes whose source_description doesn't map to a registered source are skipped and reported. Re-running the import is idempotent.
On the data from experiments/graphiti_newest_wins.py, Graphiti still answers ₹79k (a Slack message), while the ledger resolves ₹89,000 from the signed contract (examples/graphiti_import.py).