https://github.com/pyoner/typed-prompt
A set of modular TypeScript packages for composable, strongly-typed prompt engineering in AI applications.
https://github.com/pyoner/typed-prompt
ai prompt prompt-engineering prompt-toolkit typescript
Last synced: 3 months ago
JSON representation
A set of modular TypeScript packages for composable, strongly-typed prompt engineering in AI applications.
- Host: GitHub
- URL: https://github.com/pyoner/typed-prompt
- Owner: pyoner
- Created: 2025-04-21T03:19:33.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-02T10:56:29.000Z (about 1 year ago)
- Last Synced: 2025-12-20T02:25:00.681Z (5 months ago)
- Topics: ai, prompt, prompt-engineering, prompt-toolkit, typescript
- Language: TypeScript
- Homepage:
- Size: 81.1 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @typed-prompt Monorepo
A set of modular TypeScript packages for composable, strongly-typed prompt engineering in AI applications.
This monorepo provides foundational types, core utilities, and flexible formatters for transforming prompt values into various serializations (JSON, Markdown, XML), designed for seamless integration and reliable workflows.
## Why This Project Exists
This project exists to provide a standardized, type-safe framework for managing and formatting prompts in AI applications. As the use of large language models continues to evolve, ensuring consistency and flexibility in prompt generation has become critical. The project addresses the challenges of interoperability among different formats—such as JSON, Markdown, and XML—each with its own benefits and token cost implications, while meeting the varying requirements of diverse LLMs. By offering a cohesive set of utilities and formatters, developers can effortlessly integrate robust prompt engineering into their workflows, optimize performance, and minimize unnecessary overhead, ultimately fostering greater reliability and expressiveness in AI-driven experiences.
## Packages
### [@typed-prompt/types](./packages/types)
Core TypeScript type definitions for prompt values, formatters, and formatting functions used across the ecosystem.
### [@typed-prompt/core](./packages/core)
Essential utilities for formatting and handling prompt values with strong type safety and flexibility.
Relies on `@typed-prompt/types` for type definitions.
### [@typed-prompt/json-formatter](./packages/formatters/json)
Formatter package to serialize prompt values as pretty-printed JSON strings for easy integration and processing.
### [@typed-prompt/markdown-formatter](./packages/formatters/markdown)
Formatter package to convert prompt values into well-formatted Markdown for presentation or communication with AI agents.
### [@typed-prompt/xml-formatter](./packages/formatters/xml)
Formatter package to serialize prompt values as XML strings with customizable tags and indentation for workflow integration.
## Installation
Each package can be installed individually via npm:
```sh
npm install
```
Replace `` with any of the packages listed above.
## Example
```typescript
import { prompt } from '@typed-prompt/core';
import { jsonFormatter } from '@typed-prompt/json-formatter';
import { markdownFormatter } from '@typed-prompt/markdown-formatter';
import { xmlFormatter } from '@typed-prompt/xml-formatter';
const formatters = [jsonFormatter, xmlFormatter, markdownFormatter];
const complexPrompt = {
title: 'Data Processing Wizard',
instructions: [
'Analyze the input and return the structured version.',
'Highlight any inconsistencies you find.',
'Format your output according to the selected formatter.',
],
inputs: {
userData: {
name: 'string',
age: 'number',
email: 'string',
interests: ['string'],
},
meta: {
timestamp: 'Date',
source: 'string',
flags: ['string'],
},
},
outputs: [
{
type: 'success',
description: 'Structured data with formatter-specific syntax.',
},
{
type: 'error',
description: 'Error object with reason for failure.',
},
],
example: {
userData: {
name: 'Alice Example',
age: 34,
email: 'alice@example.com',
interests: ['reading', 'gardening'],
},
meta: {
timestamp: '2024-06-22T20:00:00Z',
source: 'test-suite',
flags: [],
},
},
};
const hr = '-'.repeat(20);
for (const formatter of formatters) {
const result = prompt(complexPrompt, formatter);
console.log(hr);
console.log(formatter.name);
console.log(hr);
console.log(result);
console.log(hr);
console.log('');
}
```
## Output
```sh
--------------------
jsonFormatter
--------------------
{
"prompt": {
"title": "Data Processing Wizard",
"instructions": [
"Analyze the input and return the structured version.",
"Highlight any inconsistencies you find.",
"Format your output according to the selected formatter."
],
"inputs": {
"userData": {
"name": "string",
"age": "number",
"email": "string",
"interests": [
"string"
]
},
"meta": {
"timestamp": "Date",
"source": "string",
"flags": [
"string"
]
}
},
"outputs": [
{
"type": "success",
"description": "Structured data with formatter-specific syntax."
},
{
"type": "error",
"description": "Error object with reason for failure."
}
],
"example": {
"userData": {
"name": "Alice Example",
"age": 34,
"email": "alice@example.com",
"interests": [
"reading",
"gardening"
]
},
"meta": {
"timestamp": "2024-06-22T20:00:00Z",
"source": "test-suite",
"flags": []
}
}
}
}
--------------------
--------------------
xmlFormatter
--------------------
Data Processing Wizard
Analyze the input and return the structured version.
Highlight any inconsistencies you find.
Format your output according to the selected formatter.
string
number
string
string
Date
string
string
success
Structured data with formatter-specific syntax.
error
Error object with reason for failure.
Alice Example
34
alice@example.com
reading
gardening
2024-06-22T20:00:00Z
test-suite
--------------------
--------------------
markdownFormatter
--------------------
## Prompt
- **title**: Data Processing Wizard
- **instructions**:
- Analyze the input and return the structured version.
- Highlight any inconsistencies you find.
- Format your output according to the selected formatter.
- **inputs**:
- **userData**:
- **name**: string
- **age**: number
- **email**: string
- **interests**:
- string
- **meta**:
- **timestamp**: Date
- **source**: string
- **flags**:
- string
- **outputs**:
-
- **type**: success
- **description**: Structured data with formatter-specific syntax.
-
- **type**: error
- **description**: Error object with reason for failure.
- **example**:
- **userData**:
- **name**: Alice Example
- **age**: 34
- **email**: alice@example.com
- **interests**:
- reading
- gardening
- **meta**:
- **timestamp**: 2024-06-22T20:00:00Z
- **source**: test-suite
- **flags**:
--------------------
```
## Requirements
- TypeScript ^5.x
- Node.js or compatible JavaScript runtime
## Repository
Hosted at [https://github.com/pyoner/typed-prompt](https://github.com/pyoner/typed-prompt)
## License
MIT
Developed and maintained by [Askar Yusupov](https://github.com/pyoner).