Did you ever want to SELECT * FROM clean_data_you_think_exists? Well, now you can!
A DuckDB extension that lets you query any data using natural language or run arbitrary JavaScript code directly in your SQL queries.
⚠️ WARNING: HIGHLY EXPERIMENTAL ⚠️
This extension is in early experimental stage and should be used with extreme caution.
- DO NOT use in production environments
- The generated code may be unpredictable or incorrect
- Always review the generated queries before executing
- API calls to LLMs incur costs - monitor your usage
- Proceed at your own risk!
Query any data using natural language in DuckDB, or execute JavaScript code directly! Powered by LLMs (OpenAI/Anthropic) and Deno.
Then in DuckDB:
- Rust toolchain (for building)
- Make
- Git
- Clone the repository
- Set your LLM API key (you'll need one of these)
- Build the extension
The extension will be built to:
- Debug: build/debug/wizard.duckdb_extension
- Release: build/release/wizard.duckdb_extension
Always run DuckDB in unsigned mode to load custom extensions:
Then load the extension:
The wizard extension operates with significant constraints:
What it CAN do:
- Make HTTP/HTTPS requests using Deno's built-in fetch
- Import and use any npm package via Deno's npm specifier
- Parse JSON responses natively
- Transform API responses into DuckDB tables
- Execute modern JavaScript/TypeScript code
- Cache responses for performance (60x speedup)
What it CANNOT do:
- Access the local filesystem (sandboxed)
- Make direct database connections
- Execute arbitrary system commands
The extension works by having the LLM generate JavaScript code that:
- Uses Deno's built-in fetch() for HTTP requests
- Can import npm packages like npm:yahoo-finance2 or npm:dayjs
- Returns data as an array of objects
Responses are cached to improve performance:
- Same queries return instantly from cache (60x faster)
- Cache persists for the session
- Use --bust-cache flag to force a fresh API call:
SELECT * FROM wizard('bitcoin price --bust-cache');
- Debug mode available with --debug flag to see generated code
You can also execute JavaScript code directly without going through an LLM:
The js() function:
- Executes arbitrary JavaScript/TypeScript code
- Has access to Deno's fetch API and npm packages
- Must define an async fetch_data() function that returns an array of objects
- Runs in the same sandboxed Deno environment as wizard-generated code
- Your natural language query is sent to an LLM (OpenAI or Anthropic)
- The LLM generates JavaScript code that fetches the requested data
- The code is executed in a sandboxed Deno environment
- Deno handles all HTTP requests and npm package imports
- Results are returned as a DuckDB table that you can query with SQL
The extension leverages Deno's secure runtime and built-in fetch API, plus its ability to import npm packages directly.
- "No API key found": Set your OPENAI_API_KEY or ANTHROPIC_API_KEY environment variable
- "Extension not found": Make sure you've built the extension with make release
- Rate limits: The extension uses real API calls, so you may hit rate limits with many queries
- Slow first query: The first query calls the LLM API; subsequent identical queries use cache
MIT License - see LICENSE file for details.
.png)
 4 months ago
                                14
                        4 months ago
                                14
                     
  
