Filter, classify, and score text with OpenAI Decisions, TypeSafe Jev, or Cloudflare Clef
Compatibility Matrix
This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.
| Platform | 1.5.5 | 1.5.6 | 2.0.0 | 2.0.1 |
|---|---|---|---|---|
| Linux AMD64 | ||||
| Linux ARM64 | ||||
| macOS AMD64 | ||||
| macOS ARM64 | ||||
| Windows AMD64 | ||||
| Windows ARM64 | ||||
| WebAssembly |
Installing and Loading
INSTALL decide FROM community;
LOAD decide;
Example
-- OpenAI example; use your own API key.
SET decisions_provider = 'openai';
CREATE OR REPLACE SECRET openai_key (TYPE decisions, API_KEY 'your-key', SCOPE 'decisions://openai');
SELECT decision_prob('The parcel arrived crushed.',
'Does this report physical damage?') AS probability;
About decide
decide asks decision models yes/no, multiple-choice, and rubric questions
from SQL. It supports OpenAI Decisions (the default, gpt-6-luna),
TypeSafe Jev, and Cloudflare Clef (Workers AI) with the same functions:
boolean predicates, probabilities, categorical choices, rubric scores, and
several questions at once, returned as a STRUCT with one field per
question. SELECT * FROM decision_providers() lists the providers, models,
and credential names.
Typed functions batch 20 rows per request by default; set
decisions_batch_size = 1 for independent row evaluation. Identical rows
in a chunk are sent once, and requests run 4 at a time by default
(decisions_concurrency, 1 to 32); Ctrl-C cancels requests in flight.
decision_choice_detail and decision_score_detail also return the
provider's confidence, a probability for each label, and the model version
that answered, for routing uncertain rows to review:
SELECT d.choice, d.confidence, d.probabilities['billing'] AS billing, d.model
FROM (SELECT decision_choice_detail('I was charged twice.', 'Which team?',
['support', 'billing', 'shipping']) AS d);
decision_answers_detail does the same for several questions at once.
decision_dry_run(query) reports what a query would send without sending
anything, and estimates the cost when given a token price. With
SET decisions_on_error = 'null', a failed row becomes NULL instead of
failing the query, and decision_errors() lists why each row failed. The
decision_eval_binary, decision_eval_choice, and decision_eval_score
aggregates compare answers with your own labels (agreement, kappa,
precision and recall, and a best threshold).
Upgrading from 0.2: decision_answers now returns a STRUCT instead of JSON
text, so read decision_answers(x, q).route rather than ->> paths.
Non-NULL inputs and instructions are sent to the selected provider and can incur API charges.
Credentials
Keep one decisions secret per provider, scoped to it, so each key is sent
only to its own provider. Each provider also reads an environment variable.
CREATE OR REPLACE SECRET openai_key (TYPE decisions, API_KEY 'sk-...', SCOPE 'decisions://openai');
CREATE OR REPLACE SECRET jev_key (TYPE decisions, API_KEY 'your-typesafe-key', SCOPE 'decisions://jev');
CREATE OR REPLACE SECRET cf_key (TYPE decisions, API_KEY 'workers-ai-token',
ACCOUNT_ID 'your-account-id', SCOPE 'decisions://cloudflare');
The environment variables are OPENAI_API_KEY, TYPESAFE_API_KEY, and
CLOUDFLARE_API_TOKEN with CLOUDFLARE_ACCOUNT_ID.
TypeSafe Jev and Cloudflare Clef
SET decisions_provider = 'jev'; -- default model jev-latest
SET decisions_provider = 'cloudflare'; -- default model clef; also 'clef-flash'
SET decisions_model = 'jev-1.14.0'; -- optional override; RESET when switching
SELECT decision_prob('The parcel arrived crushed.',
'Does this report physical damage?') AS probability;
Requests respect provider-specific limits; Clef caps requests at 64 questions. Neither Jev nor Clef returns refusal answers. All providers accept text only.
This is an independent integration, not an official extension of OpenAI, TypeSafe, or Cloudflare. See the README for function signatures, limits, refusal handling, and batching semantics.
Added Functions
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| decision | scalar | NULL | NULL | |
| decision_answers | scalar | NULL | NULL | |
| decision_answers_detail | scalar | NULL | NULL | |
| decision_choice | scalar | NULL | NULL | |
| decision_choice_detail | scalar | NULL | NULL | |
| decision_dry_run | table | NULL | NULL | |
| decision_errors | table | NULL | NULL | |
| decision_eval_binary | aggregate | NULL | NULL | |
| decision_eval_choice | aggregate | NULL | NULL | |
| decision_eval_score | aggregate | NULL | NULL | |
| decision_prob | scalar | NULL | NULL | |
| decision_providers | table | NULL | NULL | |
| decision_score | scalar | NULL | NULL | |
| decision_score_detail | scalar | NULL | NULL |
Overloaded Functions
This extension does not add any function overloads.
Added Types
This extension does not add any types.
Added Settings
| name | description | input_type | scope | aliases | typed_value |
|---|---|---|---|---|---|
| decisions_batch_size | Rows per request for typed functions (1 to 128) | UBIGINT | GLOBAL | [] | 20 |
| decisions_concurrency | Requests in flight at once per chunk (1 to 32); 1 sends them one at a time | UBIGINT | GLOBAL | [] | 4 |
| decisions_endpoint | Empty for the provider's URL; a loopback http://127.0.0.1 URL for mock tests | VARCHAR | GLOBAL | [] | |
| decisions_model | Model id; empty for the provider's default_model | VARCHAR | GLOBAL | [] | |
| decisions_on_error | 'fail' stops the query at the first failed row; 'null' returns NULL for failed rows and records why in decision_errors() | VARCHAR | GLOBAL | [] | fail |
| decisions_provider | Decision provider: cloudflare, jev, openai; see decision_providers() | VARCHAR | GLOBAL | [] | openai |
| temp_directory | Set the directory to which temporary files are written. | VARCHAR | GLOBAL | [] | post.db.tmp |