Promptsmith
๐ง A TypeScript library for crafting structured, maintainable system prompts using a fluent, chainable API with full type safety. It supports context, few-shot examples, guardrails against prompt injection, tool definitions with Zod, and export to Vercel AI SDK.
Install / Use
/learn @galfrevn/PromptsmithREADME
<div align="center"> <img src="./assets/banner-short.png" alt="PromptSmith Banner" width="100%" style="max-width: 1200px; border-radius: 8px;"> </div>
What is PromptSmith?
A type-safe, composable prompt builder for the Vercel AI SDK. Build production-ready AI agents with built-in security, tool integration, and token optimization.
For package documentation and API reference, see apps/core/README.md
Quick Example
import { createPromptBuilder } from "promptsmith-ts/builder";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { z } from "zod";
// Build your agent with a fluent API
const agent = createPromptBuilder()
.withIdentity("You are a helpful customer service assistant")
.withCapabilities(["Answer questions", "Process returns"])
.withTool({
name: "search_products",
description: "Search product catalog",
schema: z.object({
query: z.string().describe("Search query"),
}),
execute: async ({ query }) => {
return await db.products.search({ query });
},
})
.withGuardrails(); // Built-in security
// Deploy in one line
const response = await generateText({
model: openai("gpt-4"),
...agent.toAiSdk(),
prompt: "Find me a laptop under $1000",
});
Project Structure
This is a monorepo managed with Turbo and Bun.
promptsmith/
โโโ apps/
โ โโโ core/ # Main library package (promptsmith-ts)
โ โ โโโ src/
โ โ โ โโโ builder.ts # SystemPromptBuilder class
โ โ โ โโโ schemas.ts # Zod schema utilities
โ โ โ โโโ tester.ts # Testing framework
โ โ โ โโโ templates/ # Pre-built templates
โ โ โ โโโ types.ts # TypeScript definitions
โ โ โโโ __tests__/ # Test suite
โ โโโ docs/ # Documentation site (Next.js + Fumadocs)
โโโ assets/ # Logo and branding
โโโ CONTRIBUTING.md # Contributing guidelines
โโโ package.json # Monorepo configuration
Tech Stack
- TypeScript - Full type safety
- Zod - Runtime validation
- Vercel AI SDK - AI model integration
- Bun - Fast runtime and package manager
- Turbo - Monorepo build system
- Biome - Linting and formatting
Development
Setup
# Clone the repository
git clone https://github.com/galfrevn/promptsmith.git
cd promptsmith
# Install dependencies
bun install
Available Commands
# Development
bun dev # Start all apps in development mode
bun dev:docs # Start documentation site
# Build & Quality
bun build # Build all packages
bun test # Run all tests
bun test:coverage # Run tests with coverage
bun lint # Lint all files
bun format # Format all files
# Core library (from apps/core/)
cd apps/core
bun build # Build the library
bun test # Run library tests
Workflow
- Make changes in
apps/core/src/ - Add tests in
apps/core/__tests__/ - Run
bun testto verify - Run
bun formatto format code - Create a pull request
Key Features
- ๐ Type-Safe Tools - Zod schemas with full TypeScript support
- ๐ก๏ธ Security Built-In - One-line guardrails against prompt injection
- ๐งฉ Composable - Create base prompts and extend them
- ๐งช Testable - Built-in framework for LLM validation
- โก Token Optimization - TOON format reduces usage by 30-60%
- ๐ฆ Production Templates - Pre-built for common use cases
Format Efficiency Comparison:
toon โโโโโโโโโโโโโโโโโโโโ 15.0 โ 70.1% acc โ 4,678 tokens
csv โโโโโโโโโโโโโโโโโโโโ 14.3 โ 67.7% acc โ 4,745 tokens
json-compact โโโโโโโโโโโโโโโโโโโโ 11.0 โ 65.3% acc โ 5,925 tokens
yaml โโโโโโโโโโโโโโโโโโโโ 9.4 โ 66.7% acc โ 7,091 tokens
json-pretty โโโโโโโโโโโโโโโโโโโโ 7.5 โ 65.4% acc โ 8,713 tokens
xml โโโโโโโโโโโโโโโโโโโโ 6.8 โ 67.2% acc โ 9,944 tokens
TOON format provides the best balance of efficiency and accuracy
Comparison with Alternatives
PromptSmith stands out in the AI prompt engineering ecosystem with unique features and superior developer experience:
| Feature | PromptSmith | LangChain Prompts | Vercel AI Templates | Mastra Prompts | |---------|-------------|-------------------|---------------------|----------------| | Type Safety | โญโญโญโญโญ<br/>Full TypeScript + Zod inference | โญโญโโโ<br/>Basic typing | โญโญโญโโ<br/>Partial typing | โญโญโญโญโ<br/>Good typing | | Tool Management | โญโญโญโญโญ<br/>Auto-detection, validation | โญโญโญโโ<br/>Manual config | โญโญโญโญโ<br/>Built-in support | โญโญโญโญโ<br/>Native tools | | Pre-deployment Validation | โญโญโญโญโญ<br/>Built-in validator | โญโโโโ<br/>None | โญโญโโโ<br/>Basic checks | โญโญโญโโ<br/>Runtime only | | LLM Testing Framework | โญโญโญโญโญ<br/>Integrated tester | โญโญโโโ<br/>External tools | โญโโโโ<br/>Not included | โญโญโญโโ<br/>Basic testing | | Security Guardrails | โญโญโญโญโญ<br/>One-line built-in | โญโญโโโ<br/>Manual setup | โญโญโโโ<br/>Manual setup | โญโญโญโโ<br/>Some built-in | | Token Optimization | โญโญโญโญโญ<br/>TOON format (30-60% savings) | โญโญโโโ<br/>Standard only | โญโญโโโ<br/>Standard only | โญโญโญโโ<br/>Basic optimization | | Framework Compatibility | โญโญโญโญโญ<br/>AI SDK, Mastra, Raw | โญโญโญโโ<br/>LangChain only | โญโญโญโญโ<br/>Vercel AI SDK | โญโญโญโโ<br/>Mastra only | | Developer Experience | โญโญโญโญโญ<br/>Fluent API, autocomplete | โญโญโญโโ<br/>Functional API | โญโญโญโญโ<br/>Clean API | โญโญโญโญโ<br/>Modern API | | Production Templates | โญโญโญโญโญ<br/>7 ready-to-use | โญโญโญโโ<br/>Few examples | โญโญโโโ<br/>Basic examples | โญโญโญโโ<br/>Some templates | | Composability | โญโญโญโญโญ<br/>Merge, extend, inherit | โญโญโญโโ<br/>Limited | โญโญโโโ<br/>Basic | โญโญโญโโ<br/>Moderate |
Why Choose PromptSmith?
โ
Best-in-class type safety - Catch errors at compile time, not runtime
โ
Unique features - Validation, testing, and Mastra tool auto-detection
โ
Framework agnostic - Works with multiple AI frameworks
โ
Production ready - Built-in security, optimization, and testing
โ
Superior DX - Fluent API with full IDE autocomplete
โ
Token efficient - Save 30-60% on tokens with TOON format
Overall Rating: 9.4/10 ๐
<div align="center"> <img src="./assets/banner-large.png" alt="PromptSmith Banner" width="100%"> </div>
Contributing
We welcome contributions from the community! Whether you're fixing bugs, adding features, or improving documentation, your help is appreciated.
Please read our Contributing Guide for details on:
- Development setup and workflow
- Coding standards and best practices
- Testing requirements
- Pull request process
- How to report issues
Quick start for contributors:
# Fork and clone the repository
git clone https://github.com/galfrevn/promptsmith.git
cd promptsmith
# Install dependencies
bun install
# Make your changes, add tests, then run quality checks
bun lint && bun format && bun test
# Create a pull request
See CONTRIBUTING.md for complete guidelines.
License
MIT License - see LICENSE for details.
Links
- ๐ฆ NPM Package
- ๐ Full Documentation
- ๐ GitHub Repository
- ๐ Report Issues
- ๐ Vercel AI SDK
<div align="center"> <strong>Built with โค๏ธ for the Vercel AI SDK community</strong> </div>
ยท Made by <a href="https://github.com/galfrevn">@galfrevn</a>
ยท Hephaestus by parkjisun from <a href="https://thenounproject.com/browse/icons/term/hephaestus/" target="_blank" title="Hephaestus Icons">Noun Project</a> (CC BY 3.0)
</div>Related Skills
Writing Hookify Rules
81.1kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
openhue
329.0kControl Philips Hue lights and scenes via the OpenHue CLI.
sag
329.0kElevenLabs text-to-speech with mac-style say UX.
weather
329.0kGet current weather and forecasts via wttr.in or Open-Meteo
