A modular system for generating LLM responses by chaining prompts with different combinations of context variables.
The Prompt Chaining System is designed to automate the process of generating multiple LLM responses by systematically combining different context variables. It's particularly useful for tasks that require testing how an LLM responds to various combinations of input contexts.
Key use cases:
- Testing model responses across different scenarios
- Generating training data with varied contexts
- Systematic exploration of model behavior with different input combinations
- Modular Design – Separate components for input handling, prompt construction, model querying, and output saving
- Flexible Configuration – Support for different LLM providers through adapters
- Progress Tracking – Real-time progress updates and logging
- Error Handling – Robust error handling and logging for reliable batch processing
- Extensible – Easy to add new model adapters or modify the processing pipeline
- Python 3.8+
- pip (Python package manager)
-
Clone the repository:
git clone https://github.com/sumergoconicio/long-prompt-looper.git cd long-prompt-looper -
Create and activate a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up your environment variables:
cp .env.example .env # Edit .env with your API keys and settings
-
Environment Variables (in
.env):OPENAI_API_KEY: Your OpenAI API key (required for default LiteLLM adapter)LOG_LEVEL: Logging level (default: INFO)
-
File Structure:
project/ ├── inputs/ │ ├── var_a/ # Variable A context files │ ├── var_b/ # Variable B context files │ ├── system_prompt.txt │ └── task_prompt.txt └── outputs/ # Generated outputs
-
Prepare your input files:
- Place Variable A context files in
inputs/var_a/. Folder can be empty, in which case the script will run in fallback mode! - Place Variable B context files in
inputs/var_b/. Folder can be empty, in which case the script will run in fallback mode! - Create
system_prompt.txtandtask_prompt.txtininputs/
- Place Variable A context files in
-
Run the system:
python main.py
-
Edit
user_inputs/user_inputs.jsonto specify all required paths and prompt files. Example template:{ "var_a_dir": "inputs/var_a", "var_b_dir": "inputs/var_b", "output_dir": "outputs", "system_prompt": "inputs/system_prompt.txt", "task_prompt": "inputs/task_prompt.txt" }All runs are non-interactive and fully reproducible.
-
Run the system:
python main.py
-
Monitor progress in the console and check output files in your specified output directory.
prompt-chaining-system/
├── core/ # Core functionality
│ ├── __init__.py
│ ├── get_inputs.py # Input handling
│ ├── prompt_combiner.py # Prompt construction
│ ├── query_model.py # Model interaction
│ └── save_response.py # Output handling
├── adapters/ # Model adapters
│ ├── __init__.py
│ └── select_model.py # LiteLLM adapter
├── main.py # Entry point
├── requirements.txt # Dependencies
└── README.md # This file
Distributed under the MIT License. See LICENSE for more information.