Saved answers API
engine.answers: a person's own record of "this answered my question". It stores the typed plan behind an
answer, not SQL and not rows, and runs it again on request.
Key Modules
packages/nl2sql/src/nl2sql/api/answers_api.py(AnswersAPI, internal)packages/nl2sql/src/nl2sql/answers/models.py(SavedAnswer,SaveReport),store.py(the owner check),service.py(the logic)
Public Surface
Every method takes user_context keyword-only and required. A missing caller, or one with no user_id, is a
TypeError, not an anonymous owner.
| Method | Returns | Notes |
|---|---|---|
save(*, trace_id, conversation_id, step, user_context, note=None) |
SaveReport |
Keeps the answer of an ask step of the caller's conversation and rates its run up. |
list(*, user_context, datasource_id=None) |
List[SavedAnswer] |
Newest first. |
get(id, *, user_context) |
SavedAnswer |
|
delete(id, *, user_context) |
None |
|
run(id, *, user_context, llm_override=None, approvals=None) |
QueryResult |
Runs the plan again as the caller, with no model call (answer=False, as a tile), so it works with no key. |
SavedAnswer has id, tenant_id, user_id, question, datasource_id, plan (a ChartPlan, as a dashboard
tile holds), chart (auto by default), created_at and trace_id. SaveReport has answer, proposed,
proposal_id and not_proposed_reason.
Behaviour
- Owner only. An answer is read, run, deleted and listed only by its owner. Another caller, an admin
included, gets
AnswerNotFound(ANSWER_NOT_FOUND, 404). savetakes the plan from the stored step, the helperAddTileuses, so no model text becomes a plan. The step must have answered and kept a plan, andtrace_idmust be that step's run: otherwiseNotSavable(NOT_SAVABLE, 422). A conversation that is not the caller's isConversationNotFound.- It rates the run up through
engine.feedback, which also files the run'sverified_queryproposal when it can (originthumbs_up). The answer is saved either way:proposedisFalseandnot_proposed_reasonsays why (verified,multiple_statements,failed,no_sql,no_tracewhen the run's trace was not kept, and the other reasonsskip_reasongives).noteis stored on the rating. - A cross-database answer is filed under its first sub-query's datasource, so
list(datasource_id=...)for its other datasources does not return it. - The cap never overflows.
savecounts and stores under the owner's lock; a save that meets another in flight raisesLockHeldand can be retried. A verified answer whose source names no datasource isNotSavable. - Saving the same run twice is one answer and one proposal.
- The cap. At most
answers.max_per_useranswers (default 100) per person. The next save is refused withAnswerLimitReached(ANSWER_LIMIT_REACHED, 409) before anything is rated; deleting one frees a place. runis a normal run as the viewer: the plan goes throughplan.after, the validator, the generator, the scope and the hooks, as for any run, andapprovalsare asrun_querytakes them. A plan the schema has outgrown comes back as a result with statuserrorwhose first error haserror_codeTILE_NEEDS_FIXING, as a dashboard tile reports it. The answer is kept.- Storage.
StateStoreversion 6 (The state store).