Query files with SQL
Run SQL over files in Amazon S3, Google Cloud Storage, and SFTP connections, and join the results with warehouse tables.
This page explains how to run SQL over the files in a storage connection without loading them first. A query can read files from Amazon S3, Google Cloud Storage, or SFTP, and join them with warehouse tables.
For each question, Bobsled AI downloads the selected files into a temporary, isolated sandbox. The sandbox runs the SQL and then stops. Bobsled AI keeps no copy of the files, so each new question reads the files again.
File queries work in chat, the API, and MCP. Background Agents can't query files.
Before you begin
- Make sure that the Project has an Amazon S3, Google Cloud Storage, or SFTP connection. For more information, see Create and manage connections.
- Make sure that you have read access to the Project. Anyone with read access can query every file on the Project's storage connections.
Ask Balto to query files
In a chat, name the connection, the folder or file, and the question, as in the following example:
Sum amount by vendor for the Parquet files in orders/2026-10/ on Vendor S3, and join vendor names from Snowflake.
Balto can list the folder and inspect the columns before it writes the SQL. To see what Balto read, open Query details on the result. The following table describes the fields:
Select files
A source selects one file or a pattern inside one folder. The following table shows the selection forms:
A selection follows these rules:
- In a pattern,
*matches inside one folder level,**matches across folders, and?matches one character. - All the files in one source must have the same format and compression.
- A selection can contain up to 4,096 bytes.
Each source becomes a table with the name that you give the source. Each row also has a _source_file column that holds the name of its file. Bobsled AI rejects a file that has its own _source_file column.
Supported formats
Bobsled AI reads the format and the compression from the file name. For a compressed file, add .gz, .gzip, .zst, or .zstd after the format extension.
The following table lists the supported formats:
Check columns before a query
Balto uses describe_connection_files to read the columns of a selection. The tool reports the following:
- The column names and types, from up to the first 10 files.
- The row count, when the files give an exact count.
- Up to 50 places where a file disagrees with the others, such as a missing column or a different type.
The API operation is POST /api/v1/projects/:projectId/agent-connections/:connectionId/files/describe. The body is { "select": <selection> }.
Use the API or MCP
Send a cross-source request to POST /api/v1/projects/:projectId/run-query, or call the MCP tool data_query with action: "run_query". Both accept the same request.
The following request joins Parquet files from an S3 connection with a Snowflake table:
{
"kind": "cross-source",
"joinSql": "SELECT v.vendor_name, SUM(o.amount) FROM orders o JOIN vendors v USING (vendor_id) GROUP BY 1",
"sources": [
{
"kind": "file",
"name": "orders",
"connectionId": "S3_CONNECTION_ID",
"select": { "folder": "orders/2026-10/", "glob": "*.parquet" }
},
{
"kind": "warehouse",
"name": "vendors",
"connectionId": "SNOWFLAKE_CONNECTION_ID",
"sql": "SELECT vendor_id, vendor_name FROM DIM_VENDOR"
}
]
}Replace the following:
S3_CONNECTION_ID: the UUID of the S3 connection.SNOWFLAKE_CONNECTION_ID: the UUID of the Snowflake connection.
A request follows these rules:
- Every source must have
kind, with the value"file"or"warehouse". A request withoutkindon a source fails validation. Addkindto existing warehouse sources. - A query with one source is allowed only when that source is a file.
- An uploaded file and a storage file can't be in the same query.
How Bobsled AI detects changed files
Bobsled AI fixes the file list before it downloads anything. How it detects a change depends on the provider:
- S3 and Google Cloud Storage: Bobsled AI fixes the object version of each file. A changed object fails the query.
- SFTP: SFTP has no object version, so Bobsled AI compares each file's size and modified time. This check is best effort. If a file is overwritten with the same size and the same modified time, Bobsled AI reads the new content without an error.
If the SFTP check affects your results, ask the file owner to use new names for new data.
Export the full result
Export full result (CSV) runs the query again against the files that the answer used. Bobsled AI lists the files again and ignores files that are newer than the answer. If a file that the answer used has changed or disappeared, the export fails.
When the files changed, the card shows Full export failed and this text: The files changed since this answer. Ask again. Bobsled AI turns off Regenerate. To read the current files, ask Balto the question again.
If Bobsled AI can't reach the connection, the card doesn't show that text. Regenerate can succeed after the connection recovers.
For the export lifecycle and download rules, see Export results.
Limits
The following table lists the limits for file queries:
Bobsled AI checks the listed file sizes before it downloads anything. If the files can't finish downloading in the query time, the query stops with connection_file_rate_limited. Select fewer or smaller files.
SFTP downloads
An SFTP connection allows 2 file query downloads at the same time. Each download uses 1 SSH connection with up to 16 parallel reads. A third download fails with connection_busy. Try the query again when a download finishes.
Bobsled AI holds a lease for each running download. The lease ends when the download finishes or when the query time ends.
The lease covers file query downloads only. It doesn't count or limit these activities:
- Browsing a connection with Browse assets.
- Balto's
list_connection_filesandread_connection_filetools. - Connection tests.
- Pipeline runs.
- Another Bobsled AI connection to the same server.
If a server accepts few connections, plan for these activities together with file queries.
Errors
The following table lists the error codes and the action for each. Bobsled AI returns these codes without file contents or provider messages.
What's next
- Search by meaning: search warehouse tables with vector columns.
- Storage access and testing: set up and test storage access for a connection.
- Storage sources and destinations: load files into a warehouse with a pipeline.
