Ask a table with SQL
Using gdp.csv, write the ten countries with the highest Value in 2015 to top.csv with the columns Country Name and Value.
The task
The reference answer shows the job can be done with deft. It is not an agent run.
deft sheet query gdp.csv --sql 'select "Country Name", Value from gdp where Year = 2015 order by Value desc limit 10' -o top.csv
Input
| Country Name | Country Code | Year | Value |
| Afghanistan | AFG | 2000 | 3521418059.923445 |
| Afghanistan | AFG | 2001 | 2813571753.8725324 |
| Afghanistan | AFG | 2002 | 3825701438.9996333 |
| Afghanistan | AFG | 2003 | 4520946818.545814 |
| Afghanistan | AFG | 2004 | 5224896718.67782 |
| Afghanistan | AFG | 2005 | 6203256538.709669 |
| Afghanistan | AFG | 2006 | 6971758282.293506 |
| Afghanistan | AFG | 2007 | 9747886187.393929 |
| Afghanistan | AFG | 2008 | 10109297047.543194 |
| Afghanistan | AFG | 2009 | 12416152732.056717 |
| Afghanistan | AFG | 2010 | 15856668555.833595 |
| Afghanistan | AFG | 2011 | 17805098206.314083 |
| Afghanistan | AFG | 2012 | 19907329777.587166 |
| Afghanistan | AFG | 2013 | 20146416757.598675 |
| Afghanistan | AFG | 2014 | 20497128555.69723 |
| Afghanistan | AFG | 2015 | 19134221644.732494 |
| Afghanistan | AFG | 2016 | 18116572395.077213 |
| Afghanistan | AFG | 2017 | 18753456497.815865 |
| Afghanistan | AFG | 2018 | 18053222687.412624 |
| Afghanistan | AFG | 2019 | 18799444490.11278 |
| Afghanistan | AFG | 2020 | 19955929052.149597 |
| Afghanistan | AFG | 2021 | 14266499429.874573 |
| Afghanistan | AFG | 2022 | 14502158192.090395 |
Showing 24 of 4985 rows.
Reference output
| Country Name | Value |
| World | 75359657218242.52 |
| High income | 49773105280474.15 |
| OECD members | 47536673280840.75 |
| Post-demographic dividend | 44669765037594.52 |
| IDA & IBRD total | 27987288576613.15 |
| IBRD only | 25838353087075.664 |
| Low & middle income | 25326526306958.895 |
| Middle income | 24911694910932.1 |
| East Asia & Pacific | 21995274219766.668 |
| Europe & Central Asia | 20481460301210.54 |
How a result is judged (1 check)
- csv: file = "top.csv", rows = 11, columns = 2
Runs
CodexWithout deftPassed2026-11-07
- Time
- 12s
- New tokens
- 6.0k
- Total input
- 53.8k
- Output tokens
- 0.3k
- Commands
- 3
- Failed
- 0
Trace
I’ll inspect `gdp.csv`, select the top ten 2015 values, and write just the requested columns to `top.csv` in the current directory.
rg --files -g 'gdp.csv' -g 'AGENTS.md'output
gdp.csv
python3 -c 'import pandas as pd; d=pd.read_csv(\"gdp.csv\"); print(d.columns.tolist()); print(d.head(3).to_string(index=False))'output
['Country Name', 'Country Code', 'Year', 'Value'] Country Name Country Code Year Value Afghanistan AFG 2000 3.521418e+09 Afghanistan AFG 2001 2.813572e+09 Afghanistan AFG 2002 3.825701e+09
python3 -c 'import pandas as pd; d=pd.read_csv(\"gdp.csv\"); x=d[d[\"Year\"]==2015].nlargest(10,\"Value\")[ [\"Country Name\",\"Value\"] ]; x.to_csv(\"top.csv\",index=False); print(x.to_string(index=False))'output
Country Name Value World 7.535966e+13 High income 4.977311e+13 OECD members 4.753667e+13 Post-demographic dividend 4.466977e+13 IDA & IBRD total 2.798729e+13 IBRD only 2.583835e+13 Low & middle income 2.532653e+13 Middle income 2.491169e+13 East Asia & Pacific 2.199527e+13 Europe & Central Asia 2.048146e+13Created [top.csv](top.csv) with the ten highest 2015 `Value` rows and the requested columns. The source’s top rows include aggregates such as “World” and “High income.”
Output
| Country Name | Value |
| World | 75359657218242.52 |
| High income | 49773105280474.15 |
| OECD members | 47536673280840.75 |
| Post-demographic dividend | 44669765037594.52 |
| IDA & IBRD total | 27987288576613.15 |
| IBRD only | 25838353087075.664 |
| Low & middle income | 25326526306958.895 |
| Middle income | 24911694910932.1 |
| East Asia & Pacific | 21995274219766.668 |
| Europe & Central Asia | 20481460301210.54 |
CodexWith deft, skill installedPassedRead the skillUsed deft2026-11-07
- Time
- 21s
- New tokens
- 9.9k
- Total input
- 102.9k
- Output tokens
- 0.7k
- Commands
- 9
- Failed
- 0
Trace
I’ll inspect `gdp.csv`, identify the 2015 values, and write the ten highest rows to `top.csv` in the current directory.
cat .agents/skills/deft/SKILL.mdoutput
--- name: deft description: "Use deft first for any simple, direct operation on local files, whatever the type: convert, read, extract, edit, compress, merge, split, compare or inspect. Try it before writing a script or one-liner. If unsure, run deft find; if it says no command does this, use another tool. Not for programming work: to read, write or change source code, skip it." --- # deft One local command for file jobs. Prefer it over writing Python or shell scripts. Syntax: `deft <group> <command> [inputs] [-o output] [--options]` Groups: - `pdf`: Merge, split, compress, encrypt, forms, OCR, compare, convert - `image`: Resize, crop, convert, compress, filters, montage, OCR - `video`: Trim, crop, speed, convert, compress, GIF, frames (ffmpeg) - `audio`: Convert, trim, merge, fade, speed, tag, normalize (ffmpeg) - `doc`: Word/ODT/RTF: to text, Markdown, HTML, PDF; find and replace - `slides`: PowerPoint: extract text, Markdown outline, PDF handout - `data`: JSON/YAML/TOML/XML: convert, query with jq syntax, merge, diff - `sheet`: Excel/CSV/ODS tables: filter, sort, join, pivot, convert - `md`: Markdown to PDF, HTML, Word, EPUB; table of contents - `html`: HTML to Markdown, text, Word, PDF; screenshots - `epub`: E-books: info, to text, Markdown and PDF - `email`: EML files: headers, text, attachments - `contact`: VCF address books: to and from CSV - `calendar`: ICS calendars: to and from CSV - `gps`: GPX and KML tracks: convert, distance and time - `youtube`: Info, downlo … 849 more characters
pwd && rg --files -g 'gdp.csv'output
gdp.csv
deft find "sort CSV rows by a column and select top 10 columns"output
sheet sort sheet -> sheet Sort rows: --columns age,name --descending sheet select sheet -> sheet Keep, reorder or --drop columns sheet extract sheet -> sheet Take a sheet or range: --sheet, --range A1:D20
head -n 4 gdp.csvoutput
Country Name,Country Code,Year,Value Afghanistan,AFG,2000,3521418059.923445 Afghanistan,AFG,2001,2813571753.8725324 Afghanistan,AFG,2002,3825701438.9996333
deft sheet select --helpoutput
deft sheet select - Keep, reorder or --drop columns Usage: deft sheet select <sheet>... [-o <sheet|dir>] [options] In: sheet (each handled separately) Out: sheet (default <name>.selected.<ext>) Options: --columns <text> Columns to keep, in this order --drop <text> Columns to remove --sheet <text> Sheet name or number (default: first) --to <csv|xlsx|json> Output format (default: like the input) Common: -o --force --dry-run --json -j (deft help common) Examples: deft sheet select people.csv --columns age,name -o swapped.csv deft sheet select people.csv --drop age -o names.csv Result fields: rows, columns
deft sheet sort --helpoutput
deft sheet sort - Sort rows: --columns age,name --descending Usage: deft sheet sort <sheet>... [-o <sheet|dir>] [options] In: sheet (each handled separately) Out: sheet (default <name>.sorted.<ext>) Numbers sort as numbers; empty cells go last. Options: --columns <text> Column names or numbers, comma-separated (required) --descending Largest first --sheet <text> Sheet name or number (default: first) --to <csv|xlsx|json> Output format (default: like the input) Common: -o --force --dry-run --json -j (deft help common) Examples: deft sheet sort people.csv --columns age --descending -o ranked.csv Result fields: rows, columns
deft find "filter CSV rows where a column equals a value"output
sheet filter sheet -> sheet Keep matching rows: --where "age > 30 and city = 'Oslo'"
The file has a `Year` column and numeric `Value` data. I’m filtering to 2015, sorting by `Value` descending, then selecting the requested two columns for the output.
deft sheet filter gdp.csv --where "Year = 2015" -o <tmp> && deft sheet sort <tmp> --columns Value --descending -o <tmp> && deft sheet extract <tmp> --range A1:D11 -o <tmp> && deft sheet select <tmp> --columns "Country Name,Value" -o top.csvoutput
ok sheet.filter gdp.csv -> <tmp> 258 rows x 4 columns 0.01s ok sheet.sort <tmp> -> <tmp> 258 rows x 4 columns 0.00s ok sheet.extract <tmp> -> <tmp> 11 rows x 4 columns 0.00s ok sheet.select <tmp> -> top.csv 10 rows x 2 columns 0.00s
cat top.csvoutput
Country Name,Value World,75359657218242.52 High income,49773105280474.15 OECD members,47536673280840.75 Post-demographic dividend,44669765037594.52 IDA & IBRD total,27987288576613.15 IBRD only,25838353087075.664 Low & middle income,25326526306958.895 Middle income,24911694910932.1 East Asia & Pacific,21995274219766.668 Europe & Central Asia,20481460301210.54
Created [top.csv](top.csv) with the ten highest 2015 `Value` rows and the requested columns.
Output
| Country Name | Value |
| World | 75359657218242.52 |
| High income | 49773105280474.15 |
| OECD members | 47536673280840.75 |
| Post-demographic dividend | 44669765037594.52 |
| IDA & IBRD total | 27987288576613.15 |
| IBRD only | 25838353087075.664 |
| Low & middle income | 25326526306958.895 |
| Middle income | 24911694910932.1 |
| East Asia & Pacific | 21995274219766.668 |
| Europe & Central Asia | 20481460301210.54 |
Claude Opus 5.5Without deftPassed2026-11-07
- Time
- 15s
- New tokens
- 12.0k
- Total input
- 62.1k
- Output tokens
- 1.1k
- Commands
- 0
- Failed
- 0
Trace
Output
| Country Name | Value |
| United States | 18295019000000.0 |
| China | 11061572618578.693 |
| Japan | 4444930651964.18 |
| Germany | 3357585719351.5605 |
| United Kingdom | 2927911140916.7314 |
| France | 2439188643162.4985 |
| India | 2103588360044.3894 |
| Italy | 1836637711060.546 |
| Brazil | 1802212206904.6777 |
| Canada | 1556508816217.1401 |
Claude Opus 5.5With deft, skill installedPassedRead the skillUsed deft2026-11-07
- Time
- 16s
- New tokens
- 13.3k
- Total input
- 79.7k
- Output tokens
- 1.3k
- Commands
- 0
- Failed
- 0
Trace
Output
--- name: deft description: "Use deft first for any simple, direct operation on local files, whatever the type: create, convert, read, query, extract, edit, compress, merge, split, compare or inspect. Try it before writing a script or one-liner. If unsure, run deft find; if it says no command does this, use another tool. Not for programming work: to read, write or change source code, skip it." --- # deft One local command for file jobs. Prefer it over writing Python or shell scripts. Syntax: `deft <group> <command> [inputs] [-o output] [--options]` Groups: - `pdf`: Merge, split, compress, encrypt, forms, OCR, compare, convert - `image`: Resize, crop, convert, compress, adjust, montage, OCR - `video`: Trim, merge, convert, compress, subtitles, GIF, frames (ffmpeg) - `audio`: Convert, trim, normalize, denoise, cut silence (ffmpeg) - `doc`: Word/ODT/RTF: to text, Markdown, HTML, PDF; find and replace - `slides`: PowerPoint: extract text, Markdown outline - `sheet`: Excel/CSV/ODS tables: SQL query, pivot, merge, split, convert - `json`: JSON: convert, format, merge, diff, validate - `toml`: TOML: convert, format, merge, diff, validate - `xml`: XML: convert, format, merge, diff, validate - `yaml`: YAML: convert, format, merge, diff, validate - `md`: Markdown to PDF, HTML, Word, EPUB; table of contents - `html`: HTML to Markdown, text, Word and PDF - `epub`: E-books: info, to text, Markdown and PDF - `gps`: GPX and KML tracks: convert, distance and time - `qr`: Create QR codes and barcodes; read QR codes How to use it: 1. Run `deft <group>` to list commands, or `deft find "<what you want>"` to search. If it says `no command does this`, use another tool. 2. Run `deft <group> <command> --help` for options and examples. 3. `deft convert <in> -o <out.ext>` converts between formats by extension. 4. Results are one line starting with `ok`, `partial` or `error`; add `--json` to parse them. Errors include a `hint:` with the fix. Inputs are never overwritten; pass `--force` or `--in-place` to allow it. Globs and directories work as inputs; several inputs run in parallel. If `deft` is not installed, ask the user, then follow https://github.com/firstprayer/deft/blob/main/docs/INSTALL.md
| Country Name | Value |
| United States | 18295019000000.0 |
| China | 11061572618578.693 |
| Japan | 4444930651964.18 |
| Germany | 3357585719351.5605 |
| United Kingdom | 2927911140916.7314 |
| France | 2439188643162.4985 |
| India | 2103588360044.3894 |
| Italy | 1836637711060.546 |
| Brazil | 1802212206904.6777 |
| Canada | 1556508816217.1401 |
Claude CodeWithout deftNot run yet
Claude CodeWith deftNot run yet