Convert natural language prompts to structured JSON using OpenAI
Project description
prompt-to-json
Convert natural language prompts to structured JSON using OpenAI's GPT models.
Installation
pip install prompt-to-json
Quick Start
from prompt_to_json import PromptToJSON
# Initialize with API key
converter = PromptToJSON(api_key="sk-...") # or set OPENAI_API_KEY env var
# Convert natural language to structured JSON
prompt = "Summarize this article in 3 bullet points professionally"
result = converter.convert(prompt)
print(result)
# Output:
# {
# "task": "summarize",
# "input_data": {"type": "article", "source": "provided"},
# "output_format": {"format": "bullet_points", "count": 3},
# "constraints": {"max_points": 3},
# "config": {"tone": "professional"}
# }
Features
- 🎯 Simple API - Just one method:
convert() - 🧠 Intelligent Parsing - Uses GPT to understand intent and structure
- 📦 Structured Output - Returns clean JSON ready for downstream processing
- 🔄 Batch Processing - Convert multiple prompts at once
- ⚡ Production Ready - Error handling and fallbacks included
Usage
Basic Usage
from prompt_to_json import PromptToJSON
converter = PromptToJSON()
# Simple prompt
result = converter.convert("Extract key points from this text")
Batch Processing
prompts = [
"Summarize this article",
"Translate to Spanish",
"Extract data points"
]
results = converter.convert_batch(prompts)
Using Different Models
# Use GPT-4 for better accuracy
converter = PromptToJSON(model="gpt-4")
# Use GPT-3.5 Turbo for speed and cost efficiency (default)
converter = PromptToJSON(model="gpt-3.5-turbo")
Output Structure
The converter extracts and structures:
- task - Main action/verb (summarize, extract, generate, etc.)
- input_data - Data or content to process
- output_format - Expected format and structure
- constraints - Limitations (length, count, style, etc.)
- context - Background information or purpose
- config - Settings like tone, approach, style
Examples
# Content Generation
prompt = "Write a marketing email for our new AI product"
# Returns: {"task": "generate", "input_data": {"type": "marketing_email"}, ...}
# Data Extraction
prompt = "Extract all dates and amounts from these invoices"
# Returns: {"task": "extract", "input_data": {"type": "invoices"}, ...}
# Analysis
prompt = "Analyze customer feedback and identify top complaints"
# Returns: {"task": "analyze", "input_data": {"type": "customer_feedback"}, ...}
Requirements
- Python 3.6+
- OpenAI API key
Environment Setup
export OPENAI_API_KEY="sk-your-api-key-here"
License
MIT
Contributing
Contributions welcome! Please open an issue or submit a PR.
Support
For issues or questions, please open an issue on GitHub.
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 prompt_to_json-0.1.0.tar.gz.
File metadata
- Download URL: prompt_to_json-0.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62dfc1055251b84a9f9a66497ef7249e0673800d40af1d876f7364a364b3021d
|
|
| MD5 |
05b6b090169488ba91d7d26141ae4534
|
|
| BLAKE2b-256 |
c539f9c3421264f4e3e7ce20a40691831fe8575243797dc03c10196406f9a3be
|
Provenance
The following attestation bundles were made for prompt_to_json-0.1.0.tar.gz:
Publisher:
main.yml on OpenSoucrce/prompt-to-json
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prompt_to_json-0.1.0.tar.gz -
Subject digest:
62dfc1055251b84a9f9a66497ef7249e0673800d40af1d876f7364a364b3021d - Sigstore transparency entry: 481051718
- Sigstore integration time:
-
Permalink:
OpenSoucrce/prompt-to-json@c42da01811b55e8d5d20636166519e652e271f76 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/OpenSoucrce
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@c42da01811b55e8d5d20636166519e652e271f76 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file prompt_to_json-0.1.0-py3-none-any.whl.
File metadata
- Download URL: prompt_to_json-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85db655f40c06626d6009073c2e6540dd6b4cb69f7d26c51c9050bef78a1b2ef
|
|
| MD5 |
08e5d16828ab1fee9cf858716f98b54f
|
|
| BLAKE2b-256 |
1f2b1fd85cfafb72c88c3f7a4e7820867f81ceead88c6fd6642fa03688f86ac7
|
Provenance
The following attestation bundles were made for prompt_to_json-0.1.0-py3-none-any.whl:
Publisher:
main.yml on OpenSoucrce/prompt-to-json
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prompt_to_json-0.1.0-py3-none-any.whl -
Subject digest:
85db655f40c06626d6009073c2e6540dd6b4cb69f7d26c51c9050bef78a1b2ef - Sigstore transparency entry: 481051752
- Sigstore integration time:
-
Permalink:
OpenSoucrce/prompt-to-json@c42da01811b55e8d5d20636166519e652e271f76 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/OpenSoucrce
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@c42da01811b55e8d5d20636166519e652e271f76 -
Trigger Event:
workflow_dispatch
-
Statement type: