knowledge: typed Fact extraction via dspy native structured output #10

Merged
onibot merged 1 commits from feature/typed-facts into main 2026-10-22 14:22:05 +02:00
Owner

His direction: stop explaining string formats to the LLM and parsing
them back with Python — dspy does structured output natively and better.

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; parse_facts/parse_stop_table kept as LEGACY (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
  • 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; 22 table rows ingested cleanly
His direction: stop explaining string formats to the LLM and parsing them back with Python — dspy does structured output natively and better. **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; parse_facts/parse_stop_table kept as LEGACY (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 - 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; 22 table rows ingested cleanly
onibot added 1 commit 2026-10-22 14:22:02 +02:00
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.
onibot merged commit 2a515795e5 into main 2026-10-22 14:22:05 +02:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: onibot/floop#10