His direction: stop explaining string formats to the LLM and parsing
them back with Python — that's exactly what dspy does natively and
better. The pipe format ('subject | relation | object | quote') was
fragile (run-L verbose values, pipe-in-quote ambiguity, STOP_TABLE
string protocol).
THE CHANGE (extractor only, PR-10 scope):
- Fact(BaseModel) with subject/relation/object/quote OutputFields
- ExtractSignature.facts: list[Fact] — the adapter renders the JSON
schema into the prompt itself (verified in a live run's prompt log)
and parses responses back into typed Fact objects
- STOP_TABLE string protocol -> stop: bool OutputField
- expert.py consumes typed objects; the cand dict is built at the
check_candidate boundary only (checks.py unchanged)
- parse_facts/parse_stop_table kept as LEGACY for existing tests only
VERIFIED:
- dspy 3.4.1 pattern E2E'd first with a raw-text engine: list[Fact]
parses back as Fact objects, schema rendered in prompt (tmp probes)
- full suite 12/12 green (74 tests) — tablefrags.py updated to script
typed Fact objects
- live E2E run (ollama-cloud glm-5.3-flash, Italy rivers): correct
Po/Adige/Tiber answer; prompt log shows the native JSON schema;
table rows ingested cleanly (22 rows, quotes verbatim)
NEXT (his direction, not this PR): apply the same typed-output law to
ALL floop signatures — INIT subquestions, ROUTE engine choice,
AnswerFromKG, SelectTable, SkimPromote, Translate, VerifyCount.
Run G hung at call 8/80 for minutes with no way to see what was sent.
Reproducing it found TWO root causes, both fixed here:
1. THE 22K TABLE CHUNK WAS A PARSER BUG, not just a size problem. The
world-rivers table marks each data row's leading cell with
'!scope="row"|' (a row-label th); parse_tables flagged any row that
touched a '!' as a header row, so all 227 data rows collapsed into ONE
header of 1,825 cells and zero rows. tables_as_text then flattened
that monster into a single 22,021-char prose chunk. Fix: a row is a
header row only if ALL its cells are '!' cells; mixed rows are data
rows. Live: the world table now parses as 8 cols x 227 rows.
2. NO PROMPT OBSERVABILITY. The log's CALL/OUTPUT lines never carried
what the LM actually received. floop/llm.py now installs a dspy global
callback (PromptLogCallback): every LM call's exact rendered prompt
lands in runs/<ts>/prompts/NN-stage.txt (NN mirrors the budget counter
-- 08-EXTRACT.txt IS call 8/80), plus size/duration lines in run.log.
Stage comes from a module stack (dspy fires on_module_start with a
DIFFERENT call_id than the inner LM call -- verified with DummyLM
probes), not a call_id map.
Plus the design Emili steered (tables reach the extractor as typed
fragments, never prose dumps):
- tables_as_chunks: per-table fragments of <=40 rows, EVERY fragment
repeats header + caption, part i/N markers; the extractor always knows
which table ('troç 2/10') it is reading.
- STOP_TABLE: the extractor may early-skip a table whose subject is
wrong for the question after one fragment; fixed code skips the rest
of THAT table. ExtractSignature teaches the protocol.
- fetch_rich no longer appends the '== Tables ==' enrichment to prose
(the giant chunk's birthplace; also let verify_count cite the table as
'prose'). Tables reach the extract path only as fragments; LIST and
harvest keep reading page.tables directly.
- fragment candidates pass the same containment check against prose +
full table text; LIST answer's table never re-enters extract.
Tests: knowledge/tests/tablefrags.py (fragment generation/render,
STOP_TABLE skipping, fragment extraction with containment, prompt log
files + log lines). Live smoke: world article 10 chunks none >5k; world
table = 6 fragments (max 5,787c); Italy discharge fragment intact
(Po/1540). Full suite 47/47.
PR-1 made the skim SEE (surfaces + signals); PR-2 made it HARVEST
deterministically. PR-3 closes the loop (KNOWLEDGE.md §7):
- Skim notices: every knowledge answer's stats carry what the fetched
articles contained beyond the answer (table identities, infobox
quantities, link candidates, goal-filtered). The engine copies them
into payload['skim']; the machine renders them to the ROUTER context
('seen in passing (E1): ...') and to the run notes — later steps know
what exists and where it lives instead of re-searching blind. A notice
is a pointer, never evidence: it answers nothing by itself.
- Bounded lead promotion (Emili's 'deterministic + LLM fallback'):
quantity tables that match NO goal word are queued as leads (PR-2);
now ONE dspy call (SkimPromoteSignature) decides over the tables'
IDENTITY lines (caption/headers/rows/quantities — never the rows),
per fetched page with leads, only when leads exist. The LLM proposes;
fixed code disposes: a promoted table still passes the entity-overlap
check (a world discharge table is refused for Po/Adige/Tiber), the
named column must exist, and ingestion goes through the same
containment-checked _ingest_scalar_table as the deterministic path.
- Refactor: row ingestion extracted to _ingest_scalar_table (shared by
harvest + promotion); _entity_overlap_count shared; skim state
(_skim_notices/_skim_leads/_current_goal_question) reset per call.
- find_quantities: fix plain-digit quantities ('1540 m3/s', '1000 m3/s')
— the thousands-separator-only regex missed them, and caption+header
now join with a space ('m3/sRiver' broke the unit boundary).
Live smoke (real Wikipedia, scripted decision): goal terms without
'flow' queue both Italy tables as leads; the promoted 'Flow at the
mouth' table ingests all 27 rivers (Po 1540, Adige 235, Tiber 239
m3/s) containment-checked; promotion of the length table with a
'Flow' column name is refused (column does not exist).
Tests: 4 new (knowledge/tests/promote.py); suite 43/43 green.
A) SET GATE: enumerations are answered only from membership sets, never from mention rows (the probe early-exit that served 'Armenia, Cyprus, Georgia, Turkey' to 'what countries are in Europe' is dead). Sets carry origin_question; the gate matches stem-Jaccard>=0.5 so a set is served to its own question only. B) SETOP ENGINE: logic's first real engine — a count over list rows is computed (difference/intersection/count over norm_name'd items, table markers 'Austria*' == 'Austria'), before ROUTE, zero LLM calls, verified=True because the computation IS the check. C) Catalog honesty: knowledge 'lists are ONE fetch', logic 'how-many over lists in evidence', floop 'NOT mere size'. Plus four substrate bugs the live runs exposed: LM-proxy prompt cache (instant answers are cache hits, never trust zero latency), _context rendering list rows as scalars ('E1: 50' routed 'those countries' to user), <br> concatenation in multi-value name cells, multi-line refs leaking into values ('franceincludes the 101 departments' -> France dropped from EU -> 24 not 23). Cold E2E: Q1 50 states ingested, Q2 27 EU members ingested, Q3 difference computed = 23, cited over E1/E2. 22/22 tests.
Part 1 of the lists design (DESIGN.md §11): mechanical full ingestion, separated from epistemic answer-completeness. parse_tables rewritten as a GRID parser: cells accumulate until |- (both layouts), empty cells kept as placeholders (image cells clean to ''; dropping them shifted France rows to start at 'FRA'), rowspan/colspan expanded at placement, total_rows is the computed extent — no truncation. _clean_cell: refs/sup/File links dropped, citation templates (cref2/efn...) resolve empty, links take display text, attrs split first. LIST path in expert.py: deterministic enumeration detection OR planner-declared LIST; SELECT TABLE (one LLM call over table metadata, never rows); ingest ALL rows as member_of edges (quote = full row line, containment against stored table text); aggregate via len() — no LLM. AnswerType.LIST added; evidence payloads carry list_items + coverage. Verified live cold: 50 sovereign states from the Europe article table (51 rows - Total footer), every member with verbatim quote. 19/19 tests.