Repository navigation
knowledge.synthesize answers from datasets with a plan it checks and runs, and abstains when the task is ambiguous - #279
Merged
Merged
Conversation
…runs, and abstains when the task is ambiguous Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…e no model when none was called Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…d the evidence, and show the plan that ran Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ch column name whole Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…e answer test on the server's fake LLM Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…umn line, and keep its plan once Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…send datasets only when named Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…s output, and say what citations cover Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…documents or datasets Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…all it checks Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…aults Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #157
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
knowledge.synthesizetakesdatasets: the model proposes aknowledge.queryplan from their schemas, the server checks and runs it over every row, and the answer cites the result as[knowledge.query#1]; when the task is ambiguous the answer abstains with the question to ask.Why
The issue asks for an answer workflow that can retrieve narrative evidence, execute a validated calculation, or combine both, with optional natural-language planning that "proposes this plan; it does not acquire database privileges", and that requests clarification or abstains when table or column meaning, joins, units or time boundaries are ambiguous, never inventing joins from similar column names or answering an aggregate from retrieved rows.
knowledge.query(#278) runs a typed plan; nothing turned a question into one.Design
knowledge.synthesizegainsdatasets(up to four, asknowledge.querytakes them:source_uri,dataset_id,alias);source_urisbecomes optional, and a task names documents, datasets or both.server/knowledge/domain/answer_plan.py): one model call (knowledge_synthesize_plan) reads the task and each dataset's alias, name, row count and stored columns, and answers with a JSON object,{"plan": {...}}(theknowledge.queryfields) or{"ambiguous": "<the question to ask>"}. The instructions tell it to join only on columns the question makes clear belong together and to answer ambiguous rather than guess a column, unit, period or relation. A reply wrapped in prose or a code fence, or with braces in a note after the object, still reads (the first JSON object in it holdingplanorambiguousis read; a reply cut at its output cap is told back as incomplete JSON, even after a brace in prose, and aplanorambiguousof the wrong type is told back as such). The datasets are always the caller's: a plan's owndatasets,orgornamespaceis dropped.filtersforwhere, a group'speriodforbucket) would vanish and the plan run without it: a count of every row cited as the count asked for. A plan with a key the models do not declare, at any depth, is refused and told back (_unknown_keys); the prompt lists each field's shape, with an example.window_chars: what it may not cover and the plan that ran come first, the plan taking at most a third of it, then whole rows as many as fit, each value and each column name to 200 characters and the column line to a third of the room (so a wide selection leaves its rows room), saying how many of the rows the calculation returned are shown (and that more matched when it was cut at its limit); a cut never loses a warning.server/knowledge/app/synthesize.py): the plan is validated as aKnowledgeQueryInputin the caller's org and namespace and run byknowledge.query's handler, so it is checked against the schemas, pinned to the live snapshots, bounded by the caller-shaped ceilings and revalidated after the read exactly as a direct query is. The model never writes SQL and reaches nothing the caller could not query. A plan refused by the input model or by the query (an unknown column, a type its aggregate does not take) is proposed once more, the prompt showing the refused reply and the reason; past that the answer abstains.needs_clarificationwhen a dataset's schema needs a person's answer (before any model call;clarificationnames what to approve),ambiguouswhen the model would need to ask first (clarificationholds the question),invalid_planwhen no plan it proposed held (clarificationholds why). A dataset that is not live answers404, asknowledge.querydoes.[knowledge.query#1]. The grounding knowledge.synthesize keeps only the citations of chunks it read, and abstains on an empty answer #225 added for chunk citations covers it:knowledge.query#1joins the set of what was read, so a citation of a calculation that was not run is removed and listed inunsupported_citations.calculationsreturns the result (with each row's ids when the plan selects rows, asknowledge.queryreturns them) with its receipt (the plan as validated, the snapshots, the statement and its parameters). With no documents, the reduce runs over the calculation alone. One calculation is run an answer; with datasets,source_urisrefusesknowledge.query, the calculation's citation source.knowledge.synthesize(source_uris, task, *, datasets=...):source_urismay beNonewhen datasets are named, and every call it took still works;datasetsis sent only when named, so a documents-only call to an older server names nothing as ignored.SynthesizeCalculationisknowledge.query's output plus itscitation, so the two cannot drift apart.LLM_MAX_TOKENSentry (1,200)._reduce, unchanged, to keep the handler under the function-length gate.Alternatives considered: the model writing
knowledge.querycalls as a tool loop (several model turns per answer, and a loop to bound); retrieving rows and letting the model total them (the issue rules it out: an aggregate from retrieved rows is not over every row).Scope and risk
knowledge.queryinput in the caller's scope, checked against the schemas; it cannot name another dataset, namespace or org, and it runs as the reader user where one is set.Compatibility, rollout and rollback
datasetsand nosource_uriswith422, and one with both as it answers today, namingdatasetsan ignored argument; retried on a build N replica it calculates.knowledge.synthesizegainsdatasets(input) andcalculations,clarificationand threeabstain_reasonvalues (output);source_urisloses its minimum of one, refused only whendatasetsis empty too. No field is removed.knowledge_synthesize_planinLOOM_LLM_MAX_TOKENS_OVERRIDES.Tests
tests/unit/test_synthesize_datasets.py, 22): a reply read as a plan, a question or neither (a fenced reply, prose, braces or another object in prose before it or a note after it, a reply cut at its cap, aplanorambiguousof the wrong type, a plan beside an emptyambiguous(null, a blank string) read as the plan and beside any other value told back, no object, an object with neither key), a plan's owndatasets,organdnamespacedropped; the prompt listing each dataset's stored columns and the reason a plan was refused; the evidence showing the result, its first 50 rows and what it may not cover; the handler running the plan on the caller's datasets and scope (the model named another dataset), citing[knowledge.query#1]and removing a citation of#2, which was not run; an ambiguous task abstaining with the question and running nothing, a long question cut to 1,000 characters and ending…; an unreadable reply and a refused plan proposed again with the reason, and two refusals abstaininginvalid_plan; a schema that needs an answer abstaining before any model call (modelempty); a dataset that is not live answering404; a column name written as an instruction shown to the model and granting the plan nothing (it runs on the caller's dataset, org and namespace); the input refusing a task with neither documents nor datasets, a repeated alias, or, with datasets, a document namedknowledge.query(it would cite as the calculation does); a misnamed plan field (filters, a group'speriod) refused and told back, never run without it; a wide schema listed only to its bound, each name whole, and four datasets sharing the schema's room; a valid plan of every shape the prompt lists passing the unknown-key check; an answer that abstains on its dataset reading no document; the fake provider recognising the plan prompt; the evidence showing the plan that ran, and a note cut to fit keeping its warnings before the rows and dropping whole rows, a truncated result saying how many of its rows are shown, a long plan leaving the rows room; a value or column name holding a line break or|escaped so it stays on its row, a null shown asNULLapart from an empty string, and non-ASCII text shown unescaped in the plan as in the columns; a column name holding a line break or a comma listed in the plan prompt as one JSON string, and a dataset name written as another dataset line kept on its own line and cut; a dataset line that fits its room exactly showing every column; a plan past the query's ceilings proposed again with how to narrow it; documents and a dataset answered together (chunk and calculation citations,cited_chunksholding only the chunk);modelnamed on the abstentions that called one.tests/unit/test_sdk_agent_call.py): the SDK'ssynthesizesendsdatasetsalone and with documents, and the call it always took withoutdatasets.knowledge.synthesize, which now needssource_urisordatasets.tests/integration/test_knowledge_query_live.py): with the fake provider (the server's, as its/v1/healthreports it: a newrequire_fake_llmfixture besiderequire_real_llm), an answer over an ingested CSV runs the proposed plan over the live snapshot (5 rows, its receipt naming the snapshotknowledge.dataset_getreports) and citesknowledge.query#1; the other query tests pass (6 in all).tests/unit/test_corpus_synthesis.py) pass unchanged.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. Checked: the plan path end to end against a real server and ClickHouse with the fake provider, each abstention and the citation grounding in the tests above, and a review at every push.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code