giuliosmall/pg_typesafe on GitHub
- Stars
- 82
- Forks
- 1
- Language
- C
- License
- MIT
- Last push
- 24 Sep 2026
Read from GitHub on . Counts change daily.
Reported by the author
- One-by-one time
- 23s
23 s
github.com - Batched time
- 0.86s
0.86 s
github.com
pg_typesafe is a pre-alpha PostgreSQL extension that calls Jev directly from SQL, exposing all three question types as functions: typesafe_noul for a yes/no probability, typesafe_classify or typesafe_label for a choice among categories, typesafe_score for a rating against an ordered rubric, and typesafe_ask for mixing several questions in one request. Scalars issue one HTTP call per row, but for a table of many rows, typesafe_detect_many and typesafe_classify_many batch distinct values, sharing one request across up to typesafe.batch_size (32 by default) texts at a time.
The README demonstrates this on 1,000 closed NYC 311 complaints that reduce to 38 unique resolution strings: calling typesafe_detect once per distinct text took 23 seconds, while typesafe_detect_many, batching those same 38 strings into two TypeSafe requests instead of 38 separate HTTP calls, took 0.86 seconds, measured on a laptop against the live Jev API.
The extension keeps API keys out of SQL: the key lives in a Postgres server environment variable or a superuser-only file setting rather than in a session command that would show up in query logs. It’s tested on PostgreSQL 16 and 17.
How it uses Jev
SET typesafe.mock_response = $${
"model": "jev-latest",
"answers": {
"flag": {"type": "noul", "noul": 0.92}
},
"usage": {"input_tokens": 1, "output_tokens": 1}
}$$;
SELECT typesafe_noul('anything', 'Is this urgent?');
