A Python package for generating evaluation datasets using LLMs
Project description
Promptron
A Python package for generating evaluation datasets using Large Language Models (LLMs). Promptron helps you create structured question datasets for testing and evaluating LLM applications.
Features
- LLM-Powered Generation: Uses Ollama to generate questions automatically
- Flexible Templates: Support for multiple question types (correct, red teaming, out-of-scope, etc.)
- Configurable: Customize topics, question counts, and templates via YAML/JSON files
- Category Support: Pre-configured templates for OpenShift and Kubernetes
- Structured Output: Generates JSON datasets ready for evaluation pipelines
Installation
Prerequisites
- Python 3.8 or higher
- Ollama installed and running
- At least one Ollama model downloaded (e.g.,
llama3:latest)
Install from PyPI
pip install promptron
Install from Source
git clone <repository-url>
cd promptron
pip install -e .
Quick Start
First Time Setup
-
Install Promptron:
pip install promptron
-
Ensure Ollama is running:
ollama serve -
Download a model (default: llama3:latest):
ollama pull llama3:latest
Optional: Use a different model by setting environment variable:
export PROMPTRON_MODEL=llama3.2:latest # or create a .env file with: PROMPTRON_MODEL=llama3.2:latest
-
Initialize example config files (optional):
promptron initThis creates
topics.ymlandprompt_templates.jsonin your current directory that you can customize.
Basic Usage
Generate questions with default settings:
promptron generate
This will:
- Use the
llama3:latestmodel (v1 fixed) - Use default category and question type from
topics.ymlconfig - Read topics from the default config file
- Save output to
./artifacts/questions.json - Automatically check Ollama connection before starting
Advanced Usage
# List available categories and question types
promptron list
# Generate red teaming questions
promptron generate --question-type red_teaming
# Override default category from config
promptron generate --category kubernetes
# Override default question type from config
promptron generate --question-type red_teaming
# Use custom configuration files
promptron generate \
--topics-file my_topics.yml \
--prompt-file my_templates.json \
--output-file ./my_questions.json
# Create separate output file for each topic
promptron generate --separate-files
# Generate in JSONL format (ready for batch LLM processing)
promptron generate --output-format jsonl
# Generate in OpenAI API format (ready to send to OpenAI)
promptron generate --output-format openai
# Skip Ollama connection check (not recommended)
promptron generate --skip-check
Configuration
Topics File (YAML)
Create a topics.yml file to define your topics and question counts. You can also configure defaults and add global template variables:
# Global configuration
default_category: "openshift" # Default category to use from prompt templates
default_question_type: "correct_questions" # Default question type
# Global template configuration (optional)
# These variables will be available in all templates
template_config:
domain: "OpenShift/Kubernetes"
difficulty: "intermediate"
context: "production environment"
# Topics configuration
topics:
- name: "Pod scheduling and resource management"
count: 6
- name: "Kubernetes ingress controller"
count: 10
difficulty: "advanced" # Custom variable (overrides global)
- name: "Openshift operator life cycle management"
count: 15
context: "enterprise deployment" # Custom variable
# Optional: topic-specific template (overrides category template)
# template: "Custom template for this topic: {topic} with {count} questions..."
Available Template Variables:
{topic}- Topic name (always available){count}- Number of questions to generate (always available){category}- Category name (always available){question_type}- Question type (always available)- Any variables from
template_config(global) - Any custom variables defined per-topic
Prompt Templates (JSON)
Customize prompt templates for different question types. Templates support dynamic variables:
{
"openshift": {
"correct_questions": "You are an OpenShift SME in {domain}. Generate {count} questions about '{topic}' at {difficulty} level. Context: {context}...",
"red_teaming": "Generate {count} adversarial questions about '{topic}' in the context of {domain}...",
"out_of_scope": "Generate {count} out-of-scope questions...",
"other": "Generate {count} creative questions about '{topic}' in {context}..."
}
}
Dynamic Template Features:
- Use any variable from
template_configin your templates - Use per-topic custom variables (e.g.,
{difficulty},{context}) - Override category templates with topic-specific templates in
topics.yml - Variables are automatically available - no need to define them in templates
Example with Dynamic Variables:
{
"my_category": {
"correct_questions": "You are an expert in {domain}. Generate {count} questions about '{topic}' at {difficulty} level. Context: {context}."
}
}
This template will automatically use:
{domain}fromtemplate_config{difficulty}from topic config ortemplate_config{context}from topic config ortemplate_config
Python API
You can use Promptron programmatically in your code:
Method 1: Using YAML Config File
from promptron import generate_prompts
# Generate using YAML config file
generate_prompts(
topics_file="./my_topics.yml",
output_file="./output.json",
output_format="jsonl"
)
Method 2: Direct Prompts (Programmatic)
from promptron import generate_prompts
# Pass prompts directly without YAML file
generate_prompts(
prompts=[
{"category": "openshift", "topic": "Pod scheduling", "count": 5},
{"category": "openshift", "topic": "Ingress controller", "count": 10},
{"category": "kubernetes", "topic": "Networking", "count": 8}
],
output_format="jsonl",
single_file=True
)
Method 3: Using LLMService Directly
from promptron import LLMService
# Create service instance
service = LLMService(
topics_file="./topics.yml",
output_file="./questions.json",
output_format="openai"
)
# Generate questions
service.generate_questions(single_file=False)
# Or override config programmatically
service.config = [
{"category": "my_domain", "topic": "Topic 1", "count": 5}
]
service.generate_questions(single_file=True)
Complete Example
from promptron import generate_prompts
# Generate questions programmatically
prompts = [
{"category": "security", "topic": "Authentication", "count": 10},
{"category": "security", "topic": "Authorization", "count": 8},
{"category": "performance", "topic": "Caching", "count": 5}
]
generate_prompts(
prompts=prompts,
output_format="jsonl",
single_file=True,
output_file="./my_questions.jsonl"
)
# Output ready to use with LLM APIs!
Output Formats
Promptron supports multiple output formats optimized for different use cases. Use the --output-format flag to choose:
1. Evaluation Format (default)
Best for tracking answers from multiple LLMs:
promptron generate --output-format evaluation
{
"categories": [
{
"topic": "Pod scheduling and resource management",
"data": [
{
"user_question": "How do I configure pod resource limits?",
"app_ans": "",
"openai_ans": "",
"gemini_ans": ""
}
]
}
]
}
2. JSONL Format
Perfect for batch processing and streaming to LLMs:
promptron generate --output-format jsonl
{"prompt": "How do I configure pod resource limits?", "topic": "Pod scheduling and resource management"}
{"prompt": "What is the difference between requests and limits?", "topic": "Pod scheduling and resource management"}
3. Simple JSON Format
Clean array format for easy parsing:
promptron generate --output-format simple
[
{
"question": "How do I configure pod resource limits?",
"topic": "Pod scheduling and resource management"
},
{
"question": "What is the difference between requests and limits?",
"topic": "Pod scheduling and resource management"
}
]
4. OpenAI API Format
Ready to send directly to OpenAI API:
promptron generate --output-format openai
[
{
"messages": [
{"role": "user", "content": "How do I configure pod resource limits?"}
],
"metadata": {
"topic": "Pod scheduling and resource management"
}
}
]
5. Anthropic API Format
Ready to send directly to Anthropic API:
promptron generate --output-format anthropic
[
{
"messages": [
{"role": "user", "content": "How do I configure pod resource limits?"}
],
"metadata": {
"topic": "Pod scheduling and resource management"
}
}
]
6. Plain Text Format
Simple text file, one question per line:
promptron generate --output-format plain
# Topic: Pod scheduling and resource management
How do I configure pod resource limits?
What is the difference between requests and limits?
Using Generated Data with LLMs
Example: Using JSONL with OpenAI
import json
import openai
# Read generated prompts
with open("questions.jsonl", "r") as f:
prompts = [json.loads(line) for line in f]
# Send to OpenAI
for prompt_data in prompts:
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{"role": "user", "content": prompt_data["prompt"]}
]
)
print(f"Q: {prompt_data['prompt']}")
print(f"A: {response.choices[0].message.content}\n")
Example: Using OpenAI Format Directly
import json
import openai
# Read generated prompts (already in OpenAI format)
with open("questions.json", "r") as f:
prompts = json.load(f)
# Send directly to OpenAI
for prompt_data in prompts:
response = openai.ChatCompletion.create(
model="gpt-4",
messages=prompt_data["messages"]
)
print(response.choices[0].message.content)
Question Types
- correct_questions: Standard, technically correct questions
- red_teaming: Adversarial questions designed to test model robustness
- out_of_scope: Questions outside the domain to test boundary handling
- other: Creative, open-ended questions for design discussions
Requirements
langchain-ollama>=0.1.0pyyaml>=6.0
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Author
Hit Shiroya
- Email: 24.hiit@gmail.com
License
MIT License
Support
For issues and questions, please open an issue on the GitHub repository.
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
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 promptron-0.1.0.tar.gz.
File metadata
- Download URL: promptron-0.1.0.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7ee5e9733afd25ecc7a40f6c0431d204d167b2f6caea79420d4667d8281d894
|
|
| MD5 |
99aa95950c7c24a1f4ba3b8726cd7eba
|
|
| BLAKE2b-256 |
38173a64362e7e2e9eec896e3e405443432d3379a63eabe96f414e848662208b
|
File details
Details for the file promptron-0.1.0-py3-none-any.whl.
File metadata
- Download URL: promptron-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d12657979bbb517cff3e6e4549af7d769f7ea670cda2fa770360448242bc94c
|
|
| MD5 |
f61a4217b108e005ee07e2513158e411
|
|
| BLAKE2b-256 |
930bc38097bbff304cef9cfd7c5f17f70ad41c5bdf50774dc0be3c18634cd837
|