# Reading Query Results

A query in Studio produces two different things, and telling them apart is what keeps you out of trouble: the **raw output**, which sits inside the tool call the agent ran, and the **agent's account of it**, which is the prose and the tidy table in its reply. The first is what the query engine returned. The second is generated text about it. This page covers how to read both, and how to get a result set out of the chat when you need the whole thing.

Note
Studio does not render query output as an interactive table. There is no sorting, filtering, or export in the chat, and no execution-stats row — the output is text, and anything more structured comes from writing it to a file.

How you read a result is the same whichever source it came from. The `tdx` specifics on this page — the row cap, the output flags — apply to your Treasure Data CDP; a [connected warehouse](/products/ai-studio/query/query-execution#querying-a-connected-warehouse) returns whatever its own connector returns.

## Prerequisites

- Signed in to Treasure AI Studio ([Getting Started](/products/ai-studio/getting-started))
- A query the agent has run ([Querying Data](/products/ai-studio/query/query-execution))


## Where the Raw Output Lives

Expand the query's tool call in the chat. Inside it you get the command that ran and, below it, the output exactly as `tdx query` printed it — a monospace block, in whatever format the agent asked for (the default box-drawing table, or JSON if it used `--json`).

Two details shape what you see:

- **Long output is cut at 12 lines**, with a **Show N more lines** toggle to reveal the rest.
- **The row carries a duration badge** when the call took a second or longer, and an **Exit** badge when the command failed.


The **Copy** button on the tool call copies the command, which is the fastest way to re-run a query yourself in Treasure Code or the console.

## The Table in the Reply Is a Restatement

When the agent answers, it usually formats the numbers as a markdown table or a short summary. That table is written by the model from the output it read — it is not a rendering of the result set. Most of the time it is faithful. It can also drop a row, round a figure, or reorder columns, and nothing in the interface marks the difference.

So when a number matters, check it against the tool call rather than the prose. If the two disagree, the tool call is the record.

Warning
This applies with more force to the analysis that follows the numbers. "Revenue is up 23% because the loyalty campaign landed" contains a figure the query produced and a cause the model inferred — see [The Interpretation Is Generated Text](/products/ai-studio/concepts/reliable-answers#the-interpretation-is-generated-text).

## Getting a Full Result Set Out

`tdx query` limits itself to 40 rows only on an interactive terminal. The sandbox has none, so an unbounded query returns everything into the tool output — most of it hidden behind the truncation, and all of it taking room the AI would otherwise have for the rest of the conversation.

When you want the complete result, take it out of the chat:

1. Ask the agent to write the query to a file: `tdx query --output results.csv "SELECT ..."` (`--json`, `--jsonl`, and `--tsv` are available too)
2. Open the file in the [spreadsheet viewer](/products/ai-studio/files/file-viewers#spreadsheet-viewer) for a read-only look, with sheet tabs for a multi-sheet workbook
3. Download it from the file card or the file panel if you need it locally


A file written inside a [work folder](/products/ai-studio/concepts/work-folders) stays there after the chat is gone, which also makes this the way to keep a result past your organization's [retention period](/products/ai-studio/security/data-retention).

## Charting a Result

Treasure AI Studio has no chart engine. Ask for a chart and the agent does what it does with any other deliverable: it writes a file and opens it. Usually that is a self-contained HTML page shown in the [HTML viewer](/products/ai-studio/files/file-viewers#html-viewer); it can also be a [Mermaid diagram](/products/ai-studio/files/file-viewers#mermaid-viewer) or a plain image. There is no chart panel, no chart type menu, and nothing to configure after the fact.

That has three practical consequences:

- **Ask in words, not by picking a type.** "Plot daily signups for the last 30 days as a line chart" gets you a line chart. Describing the question instead — "show me how signups moved after the launch" — leaves the choice to the agent, which is fine until it picks something you did not want. Naming the chart is free.
- **Revising means regenerating.** The chart is a file, so a change is a new version of that file. Ask in the same chat — "make it a bar chart", "break it down by region", "sort descending" — and the agent rewrites it, with the query result still in context.
- **What it looks like depends on what wrote it.** Charting comes from the same [plugins](/products/ai-studio/files/artifacts#supported-file-formats) that supply document generation, not from Studio itself. A "dashboard" is one more HTML file on the same footing — several charts in one page — not a Studio feature with its own layout rules or saved state.


A blank chart is usually a blocked download
Chart HTML often pulls its charting library from a public CDN, and the file only renders if that request succeeds — behind a restrictive network, it will not. If a chart opens blank while the query clearly returned rows, ask the agent to inline the chart library into the file rather than loading it from a CDN, and to regenerate.

Charts are worth the same suspicion as the [table in the reply](#the-table-in-the-reply-is-a-restatement): the agent writes the data into the chart file by hand, so a chart can disagree with the query that produced it. When a chart is going in front of someone else, check a couple of its values against the tool call first.

## When a Query Fails

A failed query shows as a tool call with a warning icon and an **Exit** badge. Expand it: the engine's error text is in the output, under the statement that caused it.

| Error | Cause | What to do |
|  --- | --- | --- |
| Table not found | Wrong database or table name | Ask the agent to run `tdx databases`, then `tdx tables <db>`, and re-run against the right name |
| Column not found | Misspelled or non-existent column | Ask for `tdx describe <db.table>` and correct the query |
| Permission denied | Your account cannot read that database — or it can query the database but not download the result | Confirm the database with your administrator; the agent runs with your own permissions. A statement that runs and then fails at retrieval is the second case, which requires the **Download** database permission — see [Fetching Results Requires the CDP Download Permission](/products/ai-studio/query/query-execution#fetching-results-requires-the-cdp-download-permission) |
| Syntax error | Invalid SQL | Read the statement in the tool call. If the same shape of error keeps recurring, the SQL skills are probably off — see [Turn On the SQL Skills](/products/ai-studio/query/query-execution#turn-on-the-sql-skills) |
| Memory or resource error | The query is too heavy for Trino | Ask the agent to narrow the time range. If the query genuinely needs Hive, it has to be submitted as a job rather than run with `tdx query` — see [Trino Runs in the Chat; Hive Runs as a Job](/products/ai-studio/query/query-execution#trino-runs-in-the-chat-hive-runs-as-a-job) |


## Finding the Job in the Console

Studio does not print a job ID beside the results. To trace a query in the Treasure AI console — for the execution plan, resource usage, or logs — ask the agent to list recent jobs with `tdx jobs`, match yours by time and statement, and look that job up in the console. See [`tdx job`](/treasure-code/commands/job).

## Verification

- [ ] Expand a query's tool call and read the raw output under the command
- [ ] Compare a figure in the agent's reply against that output
- [ ] Ask for a result as a CSV file and open it in the spreadsheet viewer


## Troubleshooting

| Issue | Solution |
|  --- | --- |
| The output is cut off | Expand the tool call and use **Show N more lines**. If the result is genuinely large, write it to a file instead of reading it in the chat |
| The agent's table and the raw output disagree | Trust the tool call. Ask the agent to re-read the output and correct itself, and re-check any figure you have already acted on |
| You want to sort or filter the results | Neither is available in the chat, and the spreadsheet viewer does not sort or filter either. Re-run with `ORDER BY` / `WHERE`, or export to a file and download it to open in Excel |
| The chat became slow or forgetful after a big query | A large result leaves little room for the rest of the conversation. Start a new chat for the next question, and keep results in files — see [In-Session Memory](/products/ai-studio/chat/in-session-memory) |


## Next Steps

- [When a Query Answer Looks Wrong](/products/ai-studio/query/answer-quality) — What to check when a result or an insight looks wrong
- [Querying Data](/products/ai-studio/query/query-execution) — How a question becomes SQL, and how to review it
- [File Viewers](/products/ai-studio/files/file-viewers) — The spreadsheet viewer for exported results