TypePrompt: open-source compiler turns prompt templates into typesafe APIs in 8 languages

gepheum · reddit · 2026-11-23

A developer released TypePrompt (MIT), a compiler for prompt templates that solves the problem of prompts living in files the compiler can't check — renamed fields breaking placeholders, changed output types contradicting system prompts, few-shot examples teaching outdated JSON shapes.

How it works: each prompt is a self-contained .tp file with instructions, Input/Output schemas (a TypeScript subset), tools, and few-shot examples. Running npx @typeprompt/cli gen validates placeholder paths/types/formats, inline references, and every example at build time, then compiles to native code for TypeScript, Python, Kotlin, Rust, C++, Swift, Dart, or C#.

It's not an SDK wrapper and makes no network calls: you write one generic executePrompt helper with any SDK (OpenAI, Anthropic, Gemini, Ollama, internal gateway), and TypePrompt hands it rendered messages, strict JSON Schemas, and tool definitions, then parses/validates responses. Ships with a VS Code extension.

Original post →

More from coding & agent

coding & agent channel →