CLI tool for formatting prompts using JSON templates for different use cases
Project description
๐ JSON Prompt Formatter
A professional CLI and Python tool for converting text prompts into structured JSON/JSONL formats using customizable templates. Perfect for AI/ML workflows, API integrations, and batch processing of prompts.
โจ Features
- ๐ฅ๏ธ CLI Interface: Easy-to-use command-line interface for developers
- ๐ Batch Processing: Convert multiple prompts at once
- ๐ Multiple Templates: 7 professional templates included
- ๐ฏ Custom Placeholders: Use any placeholder format
- ๐ Dual Output: Generate both JSON and JSONL formats
- โก Fast Processing: Handle 1000+ prompts efficiently
- ๐ก๏ธ Error Handling: Comprehensive validation and error reporting
- ๐ Unicode Support: Full support for international characters
- ๐ฆ PyPI Package: Install globally with pip
๐ฆ Installation
Option 1: Install from PyPI (Recommended)
pip install json-prompt-formatter
Option 2: Install from Source
# Clone the repository
git clone https://github.com/SemTiOne/json_prompt_formatter.git
cd json_prompt_formatter
# Install in development mode
pip install -e .
Requirements
- Python 3.8+
- No external dependencies required
๐ Quick Start
CLI Usage (New!)
# Format a single prompt
json-prompt-formatter format "Create a marketing campaign for sustainable fashion" -t marketer
# Process a file
json-prompt-formatter file prompts/branding_prompts.txt -t copywriter -o my_output.json
# List available templates
json-prompt-formatter templates
# Show usage examples
json-prompt-formatter examples
# Short alias also works
jpf format "Design a minimalist logo" -t designer
Python Script Usage (Original)
python formatter.py -p prompts/branding_prompts.txt -t templates/openai_template.json -o my_formatted_prompts
๐ฏ CLI Commands
Core Commands
Format a single prompt:
json-prompt-formatter format "Your prompt text here" -t template_name [-o output_file]
Process a file:
json-prompt-formatter file input_file.txt -t template_name [-o output_file]
Batch process directory:
json-prompt-formatter batch ./input_dir ./output_dir -t template_name
List available templates:
json-prompt-formatter templates
Show examples:
json-prompt-formatter examples
CLI Examples
# Single prompt formatting
json-prompt-formatter format "Create a tagline for an AI startup" -t marketer
# File processing with output
json-prompt-formatter file prompts/marketing.txt -t copywriter -o campaign_prompts.json
# Batch processing
json-prompt-formatter batch ./prompts ./outputs -t designer
# Using short alias
jpf format "Design a mobile app interface" -t product_designer -o design_brief.json
๐ Available Templates
OpenAI Template (openai) - Complete branding analysis with structured JSON response for OpenAI ChatGPT API integration.
Copywriter Template (copywriter) - Professional copywriting prompts optimized for marketing and advertising content creation.
Designer Template (designer) - Design-focused prompt structure for visual identity, branding, and creative design work.
Marketer Template (marketer) - Marketing campaign and strategy prompts for comprehensive marketing planning and execution.
Founder Template (founder) - Business strategy and startup prompts tailored for entrepreneurship and business development.
Product Designer Template (product_designer) - UX/UI and product development prompts focused on user experience and interface design.
Prompt Engineer Template (prompt_engineer) - Advanced prompt optimization and engineering for sophisticated AI interactions.
๐ง Development Commands (Makefile)
# Development setup
make install # Install package in development mode
make clean # Clean build artifacts
make test # Run tests
# Examples and demo
make demo # Run interactive demo
make examples # Generate example outputs
make quick-test # Quick functionality test
# Building and deployment
make build # Build distribution packages
make deploy-test # Deploy to Test PyPI
make deploy # Deploy to PyPI (production)
๐ Input/Output Examples
Input Example (prompts/sample.txt)
Create a tagline for a tech startup
Write a product description for smart headphones
Develop a brand story for an eco-friendly company
CLI Command
json-prompt-formatter file prompts/sample.txt -t openai -o branded_prompts.json
Output Example (branded_prompts.json)
[
{
"model": "gpt-4o",
"temperature": 0.7,
"max_tokens": 1500,
"response_format": { "type": "json_object" },
"messages": [
{
"role": "system",
"content": "You are a world-class branding expert with 15+ years of experience..."
},
{
"role": "user",
"content": "Create a tagline for a tech startup\n\nPlease respond with a comprehensive branding analysis..."
}
],
"metadata": {
"template_version": "2.0",
"category": "branding",
"api_provider": "openai",
"tags": ["openai", "api", "branding", "structured-output"]
}
}
]
๐ฏ Advanced Usage
Python Script Usage
# Basic formatting
python formatter.py -p prompts/branding_prompts.txt -t templates/copywriter_template.json -o copywriter_prompts
# Custom output directory
python formatter.py -p prompts/my_prompts.txt -t templates/openai_template.json --output-dir results -o formatted_data
# Custom placeholder
python formatter.py -p prompts/my_prompts.txt -t templates/custom_template.json -o custom_output --placeholder "{{CUSTOM_PROMPT}}"
# Verbose logging
python formatter.py -p prompts/my_prompts.txt -t templates/openai_template.json -o debug_output --verbose
Batch Processing All Templates
# CLI approach
for template in openai copywriter designer marketer founder product_designer prompt_engineer; do
json-prompt-formatter file prompts/branding_prompts.txt -t "$template" -o "output_$template.json"
done
# Python script approach
for template in templates/*.json; do
template_name=$(basename "$template" .json)
python formatter.py -p prompts/branding_prompts.txt -t "$template" -o "output_$template_name"
done
๐ Project Structure
json_prompt_formatter/
โโโ ๐ README.md # This file
โโโ ๐ LICENSE # MIT license
โโโ ๐ CONTRIBUTING.md # Contribution guidelines
โโโ ๐ CHANGELOG.md # Version history
โโโ ๐ setup.py # Package configuration
โโโ ๐ requirements.txt # Dependencies
โโโ ๐ Makefile # Dev commands
โโโ ๐ .gitignore # Git exclusions
โโโ ๐ MANIFEST.in # Package files
โโโ ๐ package.json # Node.js package config
โโโ ๐ __main__.py # Main entry point
โโโ ๐ formatter.py # Main formatting tool
โโโ ๐ json_to_jsonl.py # Format converter
โโโ ๐ deploy.py # Deployment script
โโโ ๐ templates/ # 7 professional templates
โ โโโ openai_template.json # OpenAI API with branding expertise
โ โโโ copywriter_template.json # Marketing copywriting
โ โโโ designer_template.json # Design & visual identity
โ โโโ marketer_template.json # Marketing strategy
โ โโโ founder_template.json # Entrepreneurship & business
โ โโโ product_designer_template.json # Product design & UX/UI
โ โโโ prompt_engineer_template.json # Advanced prompt engineering
โโโ ๐ prompts/ # Sample prompt collections
โ โโโ branding_prompts.txt # 75+ branding prompts
โโโ ๐ examples/ # Usage examples & demos
โโโ ๐ outputs/ # Generated files (created automatically)
โ๏ธ CLI Options
json-prompt-formatter [COMMAND] [OPTIONS]
Commands:
format Format a single prompt
file Process prompts from a file
batch Process multiple files in a directory
templates List available templates
examples Show usage examples
Global Options:
--help Show help message
--version Show version information
Format/File Options:
-t, --template NAME Template to use (default: openai)
-o, --output FILE Output file path
โ๏ธ Python Script Options
python formatter.py [OPTIONS]
Required Arguments:
-p, --prompt PATH Path to prompt .txt file
-t, --template PATH Path to template .json file
Optional Arguments:
-o, --output NAME Base name for output files
--output-dir DIR Output directory (default: outputs)
--placeholder TEXT Placeholder to replace (default: {{prompt}})
--json-only Only generate JSON format
--jsonl-only Only generate JSONL format
--verbose, -v Enable verbose logging
๐ง Creating Custom Templates
Template Structure
{
"messages": [
{
"role": "user",
"content": "{{prompt}}"
}
],
"temperature": 0.7,
"max_tokens": 1000
}
Using Custom Templates with CLI
# Place your template in templates/ directory as my_template.json
json-prompt-formatter format "Test prompt" -t my_template
# Or use full path with Python script
python formatter.py -p prompts.txt -t path/to/custom_template.json -o output
๐ Performance
- Speed: Processes 1000+ prompts in under 10 seconds
- Memory: Efficient memory usage for large datasets
- Scalability: Tested with 10,000+ prompts
- Cross-platform: Works on Windows, macOS, and Linux
๐ Troubleshooting
CLI Issues
Command not found:
# Reinstall the package
pip uninstall json-prompt-formatter
pip install json-prompt-formatter
# Or use Python directly
python cli.py format "test prompt" -t openai
Template not found:
# List available templates
json-prompt-formatter templates
# Use correct template name
json-prompt-formatter format "prompt" -t copywriter # Not copywriter_template
Common Issues
Invalid JSON Template Error
- Check your template JSON syntax at jsonlint.com
File Not Found Error
- Verify file paths are correct
- Use forward slashes or escaped backslashes on Windows
Unicode Encoding Issues (Windows)
chcp 65001
json-prompt-formatter format "prompt with รฉmojis ๐" -t openai
๐ Publishing to PyPI
This package is available on PyPI! To publish updates:
# Test deployment
make deploy-test
# Production deployment
make deploy
๐ค Contributing
We welcome contributions! Quick steps:
- Fork the repository
- Create a feature branch
- Make your changes
- Test with both CLI and Python script
- Submit a pull request
๐ License
MIT License - see LICENSE file for details.
๐ Acknowledgments
- Built for the AI/ML developer community
- Designed for both CLI and programmatic usage
- Optimized for modern prompt engineering workflows
๐ Roadmap
- CLI interface for developers
- PyPI package distribution
- GUI interface
- Template validation tool
- Cloud storage integration
- Docker containerization
- Plugin system for custom processors
๐ก Use Cases
For Developers
# Quick prompt formatting in development
jpf format "Debug this React component" -t prompt_engineer
# Batch process training data
jpf batch ./training_prompts ./formatted_data -t openai
# CI/CD integration
json-prompt-formatter file prompts.txt -t api_template -o deployment_ready.json
For Content Teams
# Marketing campaign development
jpf file marketing_briefs.txt -t marketer -o campaign_prompts.json
# Design brief generation
jpf format "Design a modern dashboard" -t designer -o design_brief.json
For Researchers
# Experiment preparation
jpf batch ./research_prompts ./experiments -t openai
# Evaluation dataset creation
python formatter.py -p evaluation_set.txt -t research_template.json -o eval_data
โญ Star this repository if you find it helpful!
๐ฆ Follow @SemTiOne for updates
For questions or issues, please open an issue.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file json_prompt_formatter-1.0.0.tar.gz.
File metadata
- Download URL: json_prompt_formatter-1.0.0.tar.gz
- Upload date:
- Size: 26.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45da39f8af4a78939641f0af7614d07e85a35c3fff90ba1907aa1da156c17529
|
|
| MD5 |
ab23f196f38e4e856badb98b732c6c08
|
|
| BLAKE2b-256 |
d6a85a1a38bf93d0a9427176d9fe239a20e4eb8c26e2295c72c41b8aef65c774
|
File details
Details for the file json_prompt_formatter-1.0.0-py3-none-any.whl.
File metadata
- Download URL: json_prompt_formatter-1.0.0-py3-none-any.whl
- Upload date:
- Size: 28.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b7285dcd5c108757f556492ce8ae7207338105aa984ccab177e64b141579f0c
|
|
| MD5 |
1f553007438743eb65164d1d19caed6d
|
|
| BLAKE2b-256 |
3d6adbe895d6a4ea09e9b6b71f4e00d2fcd2fbb311b656250af24e60a27c1237
|