Skip to content

Collapse query tool results by default#239

Merged
cpsievert merged 9 commits into
mainfrom
collapse-query-tool-default
May 28, 2026
Merged

Collapse query tool results by default#239
cpsievert merged 9 commits into
mainfrom
collapse-query-tool-default

Conversation

@cpsievert
Copy link
Copy Markdown
Contributor

@cpsievert cpsievert commented May 22, 2026

Summary

When the query tool runs, the result card (SQL + table) starts expanded in the chat. The LLM then typically replays the same data in its follow-up response — in a markdown table or prose summary. This creates redundant, cluttered output: two copies of the same information, with the less useful one taking up prime visual space.

This PR changes the default so query tool result cards start collapsed (except for the visualize tool, where the chart is the primary content). Users can still click to expand and see the SQL query and raw results whenever they want.

Note

The Python package already has the collapsed parameter on the query tool and the visualize tool (via ggsql support). The R package does not yet have ggsql/visualize support — that work is in draft at #224. This PR should stay in draft until #224 is merged, since the R collapsed parameter and the "only visualize starts expanded" default depend on that context to be fully useful.

Related #147

What changed

  • Default collapse behavior: Only visualize starts expanded. Query, update/filter, and reset all start collapsed. The QUERYCHAT_TOOL_DETAILS env var / R option override still works as before.
  • R query tool gets collapsed parameter: Python already had this — the LLM can explicitly set collapsed=false on a per-call basis when the result table is the primary answer and should be immediately visible.
  • Updated prompts: The system prompt and tool descriptions no longer assume the user can see the raw tool result. The LLM is now guided to present key findings in its response text, use markdown tables for simple results (or show the most relevant subset for complex ones), and avoid reproducing data that's already in the expandable tool card.

Test plan

  • R tests pass (588 passed)
  • Python tests pass (388 passed)
  • Manual test: query tool results start collapsed in both R and Python apps
  • Manual test: expanding the collapsed card reveals the SQL and result table
  • Manual test: QUERYCHAT_TOOL_DETAILS=expanded overrides back to expanded
  • Manual test: LLM response includes key findings in prose/markdown rather than assuming the user saw the tool result

cpsievert and others added 9 commits May 22, 2026 17:58
The query tool result card currently starts expanded, which means the
user sees the SQL query and result table inline in the chat. The LLM
then typically reproduces that same table in its follow-up response,
creating redundancy. The LLM's markdown table is often better formatted
and more focused than the raw tool result, so the tool card ends up
being visual clutter rather than adding value.

This changes the default so only the visualize tool starts expanded
(where the chart IS the content). All other tools — query, update,
and reset — now start collapsed. Users can still expand the card to
see the SQL and raw results whenever they want, and the
QUERYCHAT_TOOL_DETAILS env var / R option still overrides the default.

Additionally:
- Adds a `collapsed` parameter to the R query tool (Python already
  had this), allowing the LLM to explicitly control the expand state
  per-call — e.g., setting collapsed=false when a result table is the
  primary answer.
- Updates system prompts and tool descriptions in both languages to
  reflect that the LLM should not assume the user has seen the raw
  tool result, and should present key findings in its response text.
- Refines the "Use Markdown tables" guideline: reproduce the full
  table for simple results, show only the most relevant subset for
  complex ones.
…efault

# Conflicts:
#	pkg-r/NEWS.md
#	pkg-r/R/querychat_tools.R
#	pkg-r/inst/prompts/prompt.md
#	pkg-r/inst/prompts/tool-query.md
@cpsievert cpsievert requested a review from gadenbuie May 27, 2026 21:31
@cpsievert cpsievert marked this pull request as ready for review May 27, 2026 21:31
@cpsievert cpsievert merged commit 888e2b9 into main May 28, 2026
23 checks passed
@cpsievert cpsievert deleted the collapse-query-tool-default branch May 28, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants