prompt-validation
Version:
Validate and standardize AI prompt outputs, detect hallucinations, enforce patterns, and auto-correct issues.
132 lines (99 loc) • 3.66 kB
Markdown
# prompt-validation
Validate, improve, and standardize AI prompt outputs.
Catch issues early, fix formatting, and craft clearer prompts for better LLM results.
<p align="center">
<a href="https://www.npmjs.com/package/prompt-validation"><img src="https://img.shields.io/npm/v/prompt-validation.svg?color=blue" alt="npm version"></a>
<a href="https://www.npmjs.com/package/prompt-validation"><img src="https://img.shields.io/npm/dt/prompt-validation.svg" alt="npm downloads"></a>
<a href="#license"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="license"></a>
<a href="https://github.com/yourname/prompt-validation/actions"><img src="https://github.com/korybantes/prompt-validation/workflows/CI/badge.svg" alt="ci"></a>
</p>
## ✨ Highlights
- 🔎 Validate text/JSON with rules (email, JSON schema, length, “no-hallucination” demo)
- 🔧 Auto-fix common formatting problems
- ✨ Improve prompts locally or via OpenAI/Gemini for better outputs
- 🧭 Incredible interactive menu (loops until quit) with banner, spinner, emojis
- ⚙️ Simple project config via `.promptvalidationrc.json`
## 📦 Install
```bash
npm install -g prompt-validation
```
## 🚀 Quick Start
### Validate
```bash
# Validate a file with rules
prompt-validation check output.txt --rules email,length-limit
# Validate JSON & auto-fix formatting
prompt-validation check response.json --rules json-schema --fix
```
If issues are fixed, a `response.json.fixed` file is written.
### Improve a prompt
```bash
# Improve prompt and print to stdout (local improver)
prompt-validation improve prompt.txt
# Improve with JSON target and save to file
prompt-validation improve prompt.txt --format json --out improved.txt
# Pipe from stdin
cat prompt.txt | prompt-validation improve - --format markdown
# Copy result to clipboard
prompt-validation improve prompt.txt --copy
```
### Interactive mode
```bash
prompt-validation interactive
```
- Loops until you choose Quit or press Ctrl+C
- Paste from clipboard, validate files, or improve prompts
## 🤖 OpenAI / Gemini (optional)
Set one of the environment variables, then add `--llm`:
```bash
# OpenAI
export OPENAI_API_KEY=sk-...
prompt-validation improve prompt.txt --llm openai --model gpt-4o-mini
# Gemini
export GEMINI_API_KEY=...
prompt-validation improve prompt.txt --llm gemini --model gemini-1.5-pro
```
Falls back to local improvement if API calls aren’t available.
## ⚙️ Config
Create `.promptvalidationrc.json`:
```json
{
"rules": ["json-schema", "length-limit", "no-hallucination"]
}
```
Running `check` without `--rules` will use these.
## 🧪 Develop
```bash
npm install
npm test
npm run build
```
## 📣 Why this CLI?
- Guardrails for LLM outputs: basic checks and fixes out-of-the-box
- Prompt enhancement: structure, constraints, evaluation criteria
- Pluggable direction: designed to add new rules and providers easily
## 🛠 Roadmap
- Custom JSON Schema path (`--schema schema.json`)
- Directory scan and glob support
- Machine-readable reports (JSON) with exit codes
- Plugin API for custom rules
## 🤝 Contributing
- See [CONTRIBUTING.md](CONTRIBUTING.md)
- Please follow the [Code of Conduct](CODE_OF_CONDUCT.md)
## 🧭 Project Links
- Homepage: https://github.com/korybantes/prompt-validation#readme
- Issues: https://github.com/korybantes/prompt-validation/issues
- npm: https://www.npmjs.com/package/prompt-validation
## 📄 License
MIT © Ertaç Toptutan