Rendering views¶
A ContextView is what an agent reads. It is plain text by default, built from ordered
blocks, fingerprinted, and rendered the same way every time for the same knowledge.
import schemaguru as sg
guru = sg.Guru.connect("duckdb:///warehouse.duckdb")
guru.measure(all=True)
guru.load_overlays("schemaguru.yaml")
view = guru.context("refund rate by month")
print(view.tokens, view.fingerprint[:12], [t.canonical() for t in view.tables])
for block in view.blocks:
print("stable" if block.stable else "scoped", block.text.splitlines()[0])
print(view.to_markdown()[:200])
print(view.to_json()[:200])
print(view.to_xml()[:200])
print(str(guru.context("refund rate by month", format="markdown"))[:80])
.text— the default format;str(view)renders the format the view was asked for (format="text" | "markdown" | "json" | "xml", or one you register)..blocks— orderedViewBlock(stable, text): the blocks that do not depend on the question (global pitfalls, the never-query list) are markedstableand come first, so a host can put a prompt-cache breakpoint after them; the legend, glossary hits and table blocks follow..tables,.tokens,.fingerprint(SHA-256 of the text),.diagnostics(for exampleSG505, how many values the value policy masked).
Profiles¶
Different agents need different shapes. Four profiles ship (profile=); the set is open.
Executor-style detail: every column with its measured facts and warnings.
Legend:
⚠ a hazard: measured, declared by a person, or drafted (then marked (draft)).
≈ / ≥ estimated from a sample of a large table; never verified.
(draft) written by a language model and not checked.
measured <date> an observed number; verified <date> a claim that passed its check.
(human, unchecked) / (declared, unchecked) stated by a person or a declaration; not yet checked against the data.
Absence of a warning is not verification.
Glossary:
active customer: ordered in the last 90 days [tables: shop.orders, shop.customers]
[shop.orders] One row per order placed on the storefront.
⚠ Pitfall: Refunds are a second row with negative amount. — fix: Filter amount > 0 for gross revenue.
⚠ WAIVED until 2027-01-31 (legacy upper-case rows being migrated): status: declared values 'paid','refunded','cancelled' — observed also 'PAID' (412 rows)
⚠ status: case drift: 'paid'/'PAID' differ only in case — compare case-insensitively
⚠ created_at: stored as VARCHAR, holds ISO-8601 date text (100% of values, measured 2026-11-24) — CAST before comparing
Answers: revenue by month; average basket size
10,000 rows (measured 2026-11-24)
live rows: (deleted IS NULL OR NOT deleted) (human, unchecked)
Columns:
order_id INTEGER PK (unique, measured 2026-11-24); ← shop.order_items.order_id (coverage 100%, measured 2026-11-24), ← shop.payments.order_id (coverage 5%, measured 2026-11-24); distinct 10,000 (measured 2026-11-24)
customer_id INTEGER → shop.customers.customer_id N:1, match 98.04% (measured 2026-11-24); distinct 1,020 (measured 2026-11-24)
account_id INTEGER → shop.accounts.account_id N:1, match 100%, coverage 40% (measured 2026-11-24); distinct 40 (measured 2026-11-24)
status VARCHAR values: 'paid','refunded','cancelled' (+ observed 'PAID'); distinct 4 (measured 2026-11-24); Payment state of the order.
created_at VARCHAR text holding ISO-8601 date text (see warning); note: ISO-8601 timestamp stored as STRING (human, unchecked); distinct 10,000 (measured 2026-11-24)
deleted BOOLEAN values: TRUE (300) (measured 2026-11-24); null 97% (measured 2026-11-24); distinct 1 (measured 2026-11-24)
Provenance: human overlay · measured 2026-11-24
Not shown: no other candidate tables.
Tables, what they answer and join paths; few columns.
Legend:
⚠ a hazard: measured, declared by a person, or drafted (then marked (draft)).
≈ / ≥ estimated from a sample of a large table; never verified.
(draft) written by a language model and not checked.
measured <date> an observed number; verified <date> a claim that passed its check.
(human, unchecked) / (declared, unchecked) stated by a person or a declaration; not yet checked against the data.
Absence of a warning is not verification.
Glossary:
active customer: ordered in the last 90 days [tables: shop.orders, shop.customers]
[shop.orders] One row per order placed on the storefront.
⚠ Pitfall: Refunds are a second row with negative amount. — fix: Filter amount > 0 for gross revenue.
⚠ WAIVED until 2027-01-31 (legacy upper-case rows being migrated): status: declared values 'paid','refunded','cancelled' — observed also 'PAID' (412 rows)
⚠ status: case drift: 'paid'/'PAID' differ only in case — compare case-insensitively
⚠ created_at: stored as VARCHAR, holds ISO-8601 date text (100% of values, measured 2026-11-24) — CAST before comparing
Answers: revenue by month; average basket size
10,000 rows (measured 2026-11-24)
Keys: PK order_id; account_id → shop.accounts.account_id (N:1, match 100%); customer_id → shop.customers.customer_id (N:1, match 98.04%)
live rows: (deleted IS NULL OR NOT deleted) (human, unchecked)
Not shown: no other candidate tables.
Keyed, parseable lines (COLUMNS, VALUES, JOIN, PK, …) for a checker model.
Legend:
⚠ a hazard: measured, declared by a person, or drafted (then marked (draft)).
≈ / ≥ estimated from a sample of a large table; never verified.
(draft) written by a language model and not checked.
measured <date> an observed number; verified <date> a claim that passed its check.
(human, unchecked) / (declared, unchecked) stated by a person or a declaration; not yet checked against the data.
Absence of a warning is not verification.
Glossary:
active customer: ordered in the last 90 days [tables: shop.orders, shop.customers]
TABLE shop.orders
PITFALL ⚠ warn: Refunds are a second row with negative amount. — fix: Filter amount > 0 for gross revenue.
WARN ⚠ WAIVED until 2027-01-31 (legacy upper-case rows being migrated): status: declared values 'paid','refunded','cancelled' — observed also 'PAID' (412 rows)
WARN ⚠ status: case drift: 'paid'/'PAID' differ only in case — compare case-insensitively
WARN ⚠ created_at: stored as VARCHAR, holds ISO-8601 date text (100% of values, measured 2026-11-24) — CAST before comparing
ROWS 10000 measured 2026-11-24
PK order_id unique measured 2026-11-24
SOFT_DELETE (deleted IS NULL OR NOT deleted) human unchecked
COLUMNS order_id INTEGER | customer_id INTEGER | account_id INTEGER | status VARCHAR | created_at VARCHAR | deleted BOOLEAN
DISTINCT order_id 10000 measured 2026-11-24
JOIN customer_id -> shop.customers.customer_id N:1 match=0.9804 coverage=1 measured 2026-11-24
DISTINCT customer_id 1020 measured 2026-11-24
JOIN account_id -> shop.accounts.account_id N:1 match=1 coverage=0.4 measured 2026-11-24
DISTINCT account_id 40 measured 2026-11-24
VALUES status declared='paid','refunded','cancelled' observed_extra='PAID':412
DISTINCT status 4 measured 2026-11-24
TYPE created_at stored_as=VARCHAR means=ISO-8601 date text rate=1 measured 2026-11-24
NOTE created_at ISO-8601 timestamp stored as STRING
DISTINCT created_at 10000 measured 2026-11-24
VALUES deleted observed=TRUE:300 measured 2026-11-24
NULLS deleted rate=0.97 measured 2026-11-24
DISTINCT deleted 1 measured 2026-11-24
Not shown: no other candidate tables.
(Each is guru.context("refund rate by month", profile=..., budget_tokens=1200) on the
measured shop with its overlay.)
Rendering rules¶
- Consequence order. Warnings come before confirmations, and truncation drops confirmations first, never warnings. A hedge is placed above what it qualifies.
- Numbers keep their method.
measured <date>,verified <date>,≈ … (sampled f%, …),≥ … (lower bound); a thin join states its coverage as a number. - Drafts are marked (draft); human statements not yet checked are marked (human, unchecked).
- Values lists are capped (
ScopeConfig.max_values_shown, 6) with "+N more". - The legend appears only when a
⚠does, and it always says: absence of a warning is not verification.
Fingerprints for CI¶
guru.fingerprint_views(questions) renders a fixed question set and returns
{question: sha256}. Commit it; after a refresh, a changed fingerprint means the prompt your
agent reads has changed — review it like code.