google/dotprompt
Executable GenAI prompt templates
Dotprompt – Executable Prompt Templates for Generative AI
What it is – Dotprompt defines a file format (.prompt) that bundles a generative‑AI prompt together with all the information needed to run it: model selection, temperature, input schema, expected output format, and Handlebars‑style placeholders. The format is language‑agnostic, and Google ships core libraries for JavaScript/TypeScript, Python, Go, Rust, and Java, plus editor extensions (VS Code, JetBrains, Vim/Emacs) and web‑based editors (Monaco, CodeMirror).
Why it matters – Prompt engineering often lives in scattered code or ad‑hoc text files. By making a prompt a self‑contained, executable artifact you can:
- Validate inputs against a schema before sending them to the model.
- Declare the model and its parameters (e.g.,
gemini-2.5-pro, temperature) right in the file. - Define the expected output format (JSON, XML, etc.) and schema, enabling automatic parsing and type‑checking.
- Reuse the same prompt across projects and languages without rewriting boilerplate.
Key components
| Component | What it provides |
|---|---|
Core libraries (dotprompt, dotpromptz, dotprompt-go, dotprompt-rs, dotprompt-java) |
Parsers, validators, and runtime helpers that read a .prompt file, fill in Handlebars variables, call the configured model, and return typed results. |
| IDE extensions (VS Code, JetBrains, Vim, Emacs) | Syntax highlighting, schema‑aware autocompletion, and one‑click “run prompt” commands inside the editor. |
| Web editors (Monaco, CodeMirror) | Embeddable editors for SaaS tools or internal dashboards. |
| Tree‑sitter grammar | Precise parsing for language‑server features and custom tooling. |
CLI (promptly) |
Run a .prompt file from the terminal, useful for quick experiments or CI pipelines. |
Typical workflow
- Create a
.promptfile – start with a YAML front‑matter block that declaresmodel,input.schema,output.format, andoutput.schema. Write the prompt body using Handlebars ({{variable}}). - Add the library – e.g.,
npm i dotprompt(JS) orpip install dotpromptz(Python). - Load the prompt in code (
ai.prompt("myPrompt")in Genkit, or the equivalent in other languages). - Call it with a plain object matching the input schema; the library handles validation, model invocation, and output parsing.
- Iterate – because the prompt is a version‑controlled file, you can track changes, roll back, and share it across teams.
Example (excerpt from the README) – a prompt that extracts structured data from free‑form text:
---
model: googleai/gemini-2.5-pro
input:
schema:
text: string
output:
format: json
schema:
name?: string, the full name of the person
age?: number, the age of the person
occupation?: string, the person's occupation
---
Extract the requested information from the given text. If a piece of information
is not present, omit that field from the output.
Text: {{text}}
Running this with the Genkit integration yields a typed JSON object like {"name":"John Doe","age":35,"occupation":"software engineer"}.
Getting started (JS/TS example shown in the README)
npm i genkit @genkit-ai/googleai # install Genkit + Google AI provider
import { genkit } from "genkit";
import { googleAI } from "@genkit-ai/googleai";
const ai = genkit({ plugins: [googleAI()] });
const extractInfo = ai.prompt("extractInfo");
const {output} = await extractInfo({text: "John Doe is a 35‑year‑old software engineer..."});
console.log(output);
Set GOOGLE_API_KEY in the environment to authenticate.
Who should use it
- Developers building AI‑augmented applications – keep prompts tidy, versioned, and type‑safe.
- Prompt engineers / data scientists – experiment with model parameters and output schemas without touching application code.
- Teams with multi‑language stacks – the same
.promptfile works in JS, Python, Go, Rust, and Java. - Tool builders – embed the web editors or CLI into internal platforms.
Community & support
- Discord channel for real‑time help: https://discord.gg/qXt5zzQKpc
- Open‑source contributions welcomed; see
GEMINI.mdfor commit conventions and testing guidelines. - CI badges show that each language implementation is continuously tested.
Dotprompt turns prompts into first‑class, executable assets, making generative‑AI development more modular, reliable, and collaborative.
Related
- Project
- Project
- Project
- Project
- Project