cd /news/ai-tools/show-hn-typeprompt-transpiles-prompt… · home › topics › ai-tools › article
[ARTICLE · art-175396] src=github.com ↗ pub= topic=ai-tools verified=true sentiment=↑ positive

Show HN: TypePrompt transpiles prompt templates to native API in 8 languages

TypePrompt, a new open-source tool, compiles `.tp` prompt template files into type-safe APIs for eight languages — TypeScript, Python, Kotlin, Rust, C++, Swift, Dart and C# — so that mismatches between application code and prompt templates surface at compile time rather than at runtime in production. Templates bundle prompt instructions, TypeScript-syntax schemas, tools and YAML few-shot examples into a single XML file, and the `npx @typeprompt/cli gen` command generates the native types and standard JSON Schemas for major LLM providers, with no framework lock-in. The tool also checks inline references to field and tool names against schemas at compile time and supports JSON, YAML, CSV and TOON input formatting.

key takeaway

TypePrompt's `npx @typeprompt/cli gen` compiles `.tp` templates into type-safe APIs across eight languages, so schema drift between app code and prompts fails at compile time instead of after the model replies.

read5 min views2 publishedNov 24, 2026
Show HN: TypePrompt transpiles prompt templates to native API in 8 languages
Image: Michielbdejong (auto-discovered)

LLM prompts that fail at build time.

Website · Docs · Quick Start · VS Code Extension · Examples

Write prompt instructions, schemas, tools, and few-shot examples in dedicated .tp files. TypePrompt compiles them into a type-safe API for your target language — with zero framework lock-in, ready to drop into whatever LLM SDK you already use.

Supported languages: TypeScript, Python, Kotlin, Rust, C++, Swift, Dart, C#

Prompt templates are plain XML files that bring together prompt instructions, schemas, tools, and few-shot examples into a single source of truth:

<!-- DecodeCatMood.tp -->

<template name="DecodeCatMood">
  <meta>
    model: gpt-4o
    temperature: 0.2
  </meta>

  <schema>
    // Variables provided to render the prompt
    interface Input {
      catAction: string;
      bowlStatus: "empty" | "half-empty";
    }

    // Structured JSON response expected from the model
    interface Output {
      demand: "feed-me" | "kneel" | "chaos";
      urgency: "chill" | "crisis";
      /** What the human servant must immediately do. */
      humanAction: string;
    }
  </schema>

  <system>
    You are an expert feline behavior interpreter.
    Decode cat actions into their true demands.
  </system>

  <user>
    <insert val="input" format="yaml" />
  </user>

  <examples>
    - input:
        catAction: Yowl at 3am
        bowlStatus: half-empty
      output:
        demand: feed-me
        urgency: crisis
        humanAction: Shake the bowl to cover the bottom.
  </examples>
</template>

npx @typeprompt/cli gen compiles your templates into a type-safe API in your target language. Here's how you use it in TypeScript:

// MyApp.ts

import { prompts } from "./gen/prompts.js";
import { executePrompt } from "./llm.js";

// 1. Render the prompt template with strongly-typed input
const prompt = prompts.decodeCatMood.render({
  catAction: "Sit on keyboard",
  bowlStatus: "half-empty",
});

// 2. Send it via your own generic helper wrapping any LLM SDK.
// It forwards the rendered messages, tools, examples, and JSON Schema,
// calls prompt.parseResponse(...), and returns the strongly-typed output.
const result = await executePrompt(prompt);

console.log(result.humanAction);
// "Surrender warm laptop and apologize for trying to work."

If your application code and your templates drift apart, your compiler or type checker catches it — not at runtime, in production, after the model replies.

Authoring

  • TypeScript-based schemas : Define types with familiar TypeScript syntax. TypePrompt generates native types and standard JSON Schemas for all major LLM providers.
  • Few-shot examples : Write examples in YAML, checked against your schemas at build time and automatically formatted using your user instructions.
  • Flexible input formatting : Render complex inputs as JSON, YAML, CSV, orTOON without changing application code.
  • Checked inline references (<c>) : Wrap field names, tool names, or inline JSON examples in<c> to verify them against your schemas at compile time so your instructions stay in sync with your types.
  • Snippets and conditional logic : Compose prompts from modular text fragments, and branch content on input values withif andswitch snippets.
  • Custom metadata : Define your ownMeta type to attach typed configuration (model, temperature, routing tags, or anything else your application needs) to each template.

Experimentation

  • Variants : Author prompt versions that share the same schemas, and pick one at runtime for A/B testing.
  • Template overrides : Inject modified templates at runtime, without rebuilding or redeploying, for fast iteration and evaluations.
  • Playground : Save sample inputs in files alongside your templates, and run them against any LLM from your IDE or the CLI.

Tooling

  • CLI : Code generation, watch mode, and a built-in formatter.
  • Editor support : VS Code extension (VS Code Marketplace ·Open VSX ) and a standalone Language Server (npx @typeprompt/language-server ).
  1. Initialize your project : Runnpx @typeprompt/cli init in your project root.
  2. Configure target languages : Edittypeprompt.yaml to specify your target language.
  3. Generate code : Runnpx @typeprompt/cli gen , or pass--watch for automatic regeneration on file changes.

See the Quick start guide for a full walkthrough.

Using an AI coding agent? Install the TypePrompt skill so your agent (Claude Code, Cursor, Codex, etc.) knows the .tp syntax and CLI:

npx skills add gepheum/typeprompt

TypePrompt gets its type safety from code generation. The schemas in your template files are the source of truth: TypePrompt translates them into native types in your application's language. The code that fills in a template and the code that reads the model's response are generated from the same definition as the prompt itself, so they can't drift apart.

TypePrompt is not an LLM client, and doesn't wrap one. It only renders prompts and parses responses. You send the request with whichever SDK you already use.

In practice, this rules out bugs that other approaches only catch at runtime, if at all:

  • Mismatched placeholders. With runtime prompt files (Dotprompt, Prompty) or framework templates (LangChain, Semantic Kernel), renaming a variable on one side and not the other fails at runtime, or silently sends an incomplete prompt.
  • Output types written twice. When the schema lives in the prompt file and the type lives in your code, nothing keeps the two in sync.
  • Stale few-shot examples. Examples are usually hand-written text that no tool checks. After a schema change, they keep teaching the model the old shape.

BAML also generates types from prompt files. The main differences: TypePrompt checks few-shot examples, doesn't make the LLM call itself, and uses TypeScript type syntax instead of a custom language.

Released under the MIT License.

── more in #ai-tools 4 stories · sorted by recency
── more on @typeprompt 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/show-hn-typeprompt-t…] indexed:0 read:5min 2026-11-24 · —