Skip to main content

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

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:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test with both CLI and Python script
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json_prompt_formatter-1.0.0.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json_prompt_formatter-1.0.0-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

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

Hashes for json_prompt_formatter-1.0.0.tar.gz
Algorithm Hash digest
SHA256 45da39f8af4a78939641f0af7614d07e85a35c3fff90ba1907aa1da156c17529
MD5 ab23f196f38e4e856badb98b732c6c08
BLAKE2b-256 d6a85a1a38bf93d0a9427176d9fe239a20e4eb8c26e2295c72c41b8aef65c774

See more details on using hashes here.

File details

Details for the file json_prompt_formatter-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for json_prompt_formatter-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b7285dcd5c108757f556492ce8ae7207338105aa984ccab177e64b141579f0c
MD5 1f553007438743eb65164d1d19caed6d
BLAKE2b-256 3d6adbe895d6a4ea09e9b6b71f4e00d2fcd2fbb311b656250af24e60a27c1237

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page