Transform natural language into ready-to-use workflow automation configurations.
Instead of manually writing complex JSON configurations for your workflow automation tools, just describe what you want in plain English. The system retrieves similar examples from its knowledge base, generates valid JSON configs, and validates them against your schema.
The Challenge:
- Workflow automation tools (Zapier, n8n, Apache Airflow, custom systems) require precise JSON configurations
- Writing these configs manually is time-consuming and error-prone
- Remembering field names, structure, and syntax is tedious
- Copying and modifying existing configs leads to inconsistencies
The Solution:
- Type what you want in plain English: "Send email when task exceeds 2 hours"
- Get valid JSON automatically generated and validated
- Use it anywhere - workflow tools, APIs, configuration files
You want: "Escalate high-priority tickets to manager if unresolved for 24 hours"
You get: JSON config that your ticketing system can execute
{
"nodeType": "escalation",
"conditions": [
{"field": "priority", "op": "==", "value": "high"},
{"field": "unresolved_duration", "op": ">", "value": 86400}
],
"actions": [
{"type": "assign", "params": {"assignee": "manager"}}
]
}You want: "Send SMS alert when server CPU usage exceeds 80%"
You get: Config for your monitoring system (Prometheus, Datadog, etc.)
You want: "Auto-approve expense reports under $100, otherwise route to finance team"
You get: Config for your approval workflow engine
You want: "Retry failed API calls 3 times with exponential backoff"
You get: Config for Apache Airflow or custom ETL pipelines
You want: "Create Slack notification when customer satisfaction score drops below 3"
You get: Config for your customer feedback system
This is a Retrieval-Augmented Generation (RAG) system - it doesn't just guess, it learns from examples.
1. 🔍 RETRIEVE
Your query: "notify when task is late"
→ Finds 3 most similar examples from knowledge base
2. 📝 BUILD PROMPT
→ Combines: Schema rules + Retrieved examples + Your request
→ Creates comprehensive instruction for LLM
3. 🤖 GENERATE
→ Sends to OpenAI (or shows offline placeholder)
→ Gets back JSON workflow configuration
4. ✅ VALIDATE
→ Checks against JSON Schema
→ Ensures all required fields present
→ Reports validation errors or success
Why RAG? By showing the AI relevant examples first, you get more consistent, accurate outputs that follow your existing patterns.
- Python 3.10 or higher
- pip (Python package manager)
git clone https://github.com/Evalutik/workflow-assistant-rag.git
cd workflow-assistant-ragWindows (PowerShell):
python -m venv venv
venv\Scripts\activateLinux/Mac:
python -m venv venv
source venv/bin/activatepip install -r requirements.txtThis installs:
flask- Web application frameworkscikit-learn- TF-IDF retrieval enginejsonschema- Config validationrequests- LLM API callspython-dotenv- Environment variable managementpandas,numpy- Data processing
The app works perfectly without an API key - it runs in demo mode with simulated responses.
To enable real AI generation, create a .env file in the project root:
OPENAI_API_KEY=sk-your-api-key-hereThat's it! The system automatically detects the API key and switches to real AI mode. No code editing needed!
Get an API key: OpenAI Platform
Note: In offline mode, the system shows you what prompt would be sent to the AI and generates valid example configs for demonstration.
python demo.pyYou should see the complete pipeline in action with sample outputs.
workflow-assistant-rag/
├── data/
│ ├── examples.json # 6 example workflow configurations
│ └── schema.json # JSON Schema for workflow validation
├── retriever.py # TF-IDF-based example retrieval
├── prompt_builder.py # LLM prompt construction
├── llm_client.py # LLM API client (offline mode supported)
├── validate.py # JSON Schema validation
├── utils.py # Utility functions (JSON I/O, logging)
├── demo.py # Command-line demo script
├── app.py # Flask web application
├── requirements.txt # Python dependencies
└── README.md # This file
-
Start the Flask server:
python app.py
-
Open your browser:
http://127.0.0.1:5000/
-
Enter your request:
- Type: "Send email notification when task duration exceeds 2 hours"
- Click "Generate Workflow"
-
Review the results:
- See which examples were retrieved
- View the generated prompt
- Check the JSON output
- Review validation status
-
Download or copy the JSON to use in your workflow system
Run the complete pipeline with a sample query:
python demo.pyWhat you'll see:
- Loading of schema and examples
- TF-IDF index building
- Top-3 retrieved examples
- Complete LLM prompt (500+ chars preview)
- Generated JSON configuration
- Validation results with coverage metrics
Once you have the web app or demo running, try these:
| Natural Language Query | Expected Output Type |
|---|---|
| "Send email when task takes longer than 2 hours" | Notification workflow |
| "Escalate to manager if customer rating is below 3" | Escalation workflow |
| "Retry failed API calls 3 times" | Retry logic workflow |
| "Send SMS alert for critical system errors" | Alert workflow |
| "Auto-assign complex tasks to senior team" | Routing workflow |
| "Generate weekly performance report every Friday" | Scheduled task workflow |
JSON Workflow Configuration with these components:
{
"nodeType": "notification", // Type of automation
"conditions": [ // When to trigger
{
"field": "duration",
"op": ">",
"value": 7200
}
],
"actions": [ // What to do
{
"type": "email",
"params": {
"recipients": ["team@example.com"],
"subject": "Task Duration Alert"
}
}
],
"priority": "high" // Optional metadata
}-
Workflow Automation Tools:
- Import into n8n, Zapier, Make.com
- Configure Apache Airflow DAGs
- Set up automation rules in ticketing systems
-
Custom Applications:
- Save as configuration file (
.json) - Store in database for runtime processing
- Send to your workflow engine API
- Save as configuration file (
-
CI/CD Pipelines:
- Define deployment workflows
- Configure build triggers
- Set up automated testing rules
Edit data/examples.json to include your organization's workflow patterns:
[
{
"id": "custom-001",
"title": "Your workflow title",
"description": "One-sentence description",
"config": {
"nodeType": "your_type",
"conditions": [...],
"actions": [...]
}
}
]Tip: The more examples you add, the better the system understands your specific use cases!
Edit data/schema.json to match your workflow system's requirements:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
// Define your fields here
},
"required": ["field1", "field2"] // Mandatory fields
}The validator will ensure all generated configs match your schema.
workflow-assistant-rag/
├── data/
│ ├── examples.json # Knowledge base (6 workflow examples)
│ └── schema.json # JSON Schema for validation
├── retriever.py # TF-IDF similarity search
├── prompt_builder.py # Prompt construction logic
├── llm_client.py # OpenAI API client (offline-capable)
├── validate.py # JSON Schema validation
├── utils.py # Helper functions
├── demo.py # CLI demonstration
├── app.py # Flask web application
├── requirements.txt # Python dependencies
└── README.md # Documentation
┌─────────────────────────────────────────────────────────────┐
│ USER INPUT │
│ "Send email when task duration > 2 hours" │
└────────────────┬────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ RETRIEVER (retriever.py) │
│ • Loads examples from data/examples.json │
│ • Builds TF-IDF index │
│ • Finds 3 most similar examples via cosine similarity │
└────────────────┬────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ PROMPT BUILDER (prompt_builder.py) │
│ • Combines: Schema + Retrieved examples + User query │
│ • Formats structured prompt for LLM │
└────────────────┬────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ LLM CLIENT (llm_client.py) │
│ • Calls OpenAI API (if key available) │
│ • Returns offline placeholder (if no key) │
│ • Parses JSON from response │
└────────────────┬────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ VALIDATOR (validate.py) │
│ • Validates JSON against schema (data/schema.json) │
│ • Computes coverage metric (% required fields) │
│ • Returns errors or success status │
└────────────────┬────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ OUTPUT │
│ Valid JSON workflow configuration ready to use │
└─────────────────────────────────────────────────────────────┘
- Flask - Web framework for interactive interface
- scikit-learn - TF-IDF vectorization and cosine similarity
- jsonschema - JSON Schema validation (Draft-07)
- OpenAI API - LLM generation (optional, works offline)
- python-dotenv - Environment configuration
This prototype uses TF-IDF (Term Frequency-Inverse Document Frequency) for simplicity and zero external dependencies:
✅ Pros:
- No API calls needed for retrieval
- Fast and deterministic
- Works offline
- Easy to understand
- Keyword-based (doesn't understand deep semantics)
- Misses synonyms ("delayed" vs "late")
For Production: Consider upgrading to:
- Vector embeddings (OpenAI embeddings, Sentence Transformers)
- Vector databases (Pinecone, Weaviate, ChromaDB)
- Semantic search capabilities
What is Offline Mode?
When you don't have an OpenAI API key set, the system runs in offline mode to let you explore the full pipeline without costs.
What Happens:
- ✅ Retrieval still works - Finds similar examples from your knowledge base
- ✅ Prompt is built - Shows you exactly what would be sent to the LLM
⚠️ No actual API call - Instead of calling OpenAI, returns a placeholder- ✅ Simulated output - Creates a fake but valid JSON response for demo
- ✅ Validation works - Checks the simulated output against schema
Why is this useful?
- Learn how RAG works without spending money
- Test your examples and schema before going live
- See the complete prompt to understand what the LLM receives
- Experiment with queries to refine your knowledge base
To Enable Real AI:
- Get API key from OpenAI
- Create
.envfile:OPENAI_API_KEY=sk-your-key-here - Restart the app - it automatically switches to AI mode!
Test retrieval only:
python retriever.pyTest prompt building:
python prompt_builder.pyTest validation:
python validate.pyTest LLM client:
python llm_client.pyEach module has a __main__ block demonstrating its functionality.
Example: Using in a Python script
from retriever import load_examples, build_index, get_top_k
from prompt_builder import build_prompt
from llm_client import call_llm, parse_llm_text_to_json
from validate import validate_output
from utils import load_json
# Load your data
schema = load_json("data/schema.json")
examples = load_examples("data/examples.json")
# Build index once
vectorizer, matrix, _ = build_index(examples)
# Process user query
query = "Send alert when CPU > 80%"
retrieved = get_top_k(query, vectorizer, matrix, examples, k=3)
prompt = build_prompt(query, retrieved, schema)
# Get LLM response
result = call_llm(prompt)
config, error = parse_llm_text_to_json(result.get("text", "{}"))
# Validate
is_valid, errors = validate_output(config, schema)
if is_valid:
# Use the config in your system
print("Generated config:", config)
else:
print("Validation errors:", errors)Issue: FileNotFoundError: data/examples.json
- Solution: Make sure you're running commands from the project root directory
- Check:
ls data/should showexamples.jsonandschema.json
Issue: ModuleNotFoundError: No module named 'flask'
- Solution: Activate virtual environment and install dependencies
- Run:
pip install -r requirements.txt
Issue: Import errors or missing modules
- Solution: Ensure virtual environment is activated
- Windows:
venv\Scripts\activate - Linux/Mac:
source venv/bin/activate
Issue: Schema validation always fails
- Solution: Check that your
data/schema.jsonmatches the structure in examples - Verify: Required fields in schema match your example configs
Issue: Retrieval returns irrelevant examples
- Solution: Add more diverse examples to
data/examples.json - Tip: Include examples with varied terminology and use cases
Issue: Web app shows "offline mode" but I have an API key
- Solution: Uncomment the API request code in
llm_client.py(see line ~45) - Note: By default, API calls are commented out for safety
- Check the inline comments in each Python file
- Run individual modules to test components
- Review
demo.pyfor a working example of the full pipeline
For production:
1. Retrieval System:
- Use vector database (Pinecone, Weaviate, ChromaDB)
2. LLM Integration:
- Add rate limiting and request queuing
- Monitor token usage and costs
3. Validation:
- Create custom error messages for your domain
4. Features:
- User authentication and authorization
- Usage analytics and logging
- A/B testing for prompt variations
- Feedback loop to improve examples
- Version control for schemas and examples
- API endpoints for programmatic access
5. Infrastructure:
- Containerization (Docker)
- Horizontal scaling
- Monitoring and alerting
- Database for storing generated configs
Feel free to:
- Fork and adapt for your specific use case
- Add more sophisticated retrieval methods
- Integrate with other LLM providers
- Extend validation logic
- Improve the web interface
MIT License - See LICENSE file for details
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows
pip install -r requirements.txtpython app.py
# Open http://127.0.0.1:5000/python demo.pyCreate .env file:
OPENAI_API_KEY=sk-your-key-here
Edit data/examples.json with your workflows
Edit data/schema.json to match your system
Questions? Review the inline comments in the Python files or run python <module>.py to see demonstrations of individual components.