Generative AI is transforming business processes, and nowhere is this more evident than in automated approval workflows. Prompt engineering—the art and science of crafting effective instructions for large language models (LLMs)—is the linchpin for reliable, auditable, and scalable AI-driven approvals. As we covered in our Ultimate Guide to Automating Approval Workflows with AI in 2026, the right prompts can make or break your automation project. This deep dive explores exactly how to design, build, and test robust prompts for approval workflows, with hands-on code samples and practical troubleshooting.
Whether you're automating expense approvals, procurement sign-offs, or HR onboarding, this tutorial will give you the tools and techniques to engineer prompts that drive accurate, compliant, and auditable decisions. For a broader look at workflow automation, see our guide on optimizing prompt chaining for business process automation.
Prerequisites
- Python 3.10+ (tested with 3.11)
- OpenAI API Key (or Azure OpenAI, or Hugging Face Inference API)
- openai Python package
v1.2.3or later - Basic knowledge of approval workflows (e.g., expense, procurement, HR)
- Familiarity with REST APIs and JSON
- Optional: Access to a workflow automation tool (e.g., Zapier, n8n, or custom backend)
Step 1: Set Up Your Environment
-
Install Python and Required Packages
python3 -m venv venv source venv/bin/activate pip install openai==1.2.3 python-dotenv
-
Set Your API Key
Create a.envfile in your project directory:OPENAI_API_KEY=sk-...
Never commit your API key to version control. -
Test Your Setup
Create a filetest_openai.py:
Run:import openai import os from dotenv import load_dotenv load_dotenv() openai.api_key = os.getenv('OPENAI_API_KEY') response = openai.chat.completions.create( model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Say hello!"}] ) print(response.choices[0].message.content)python test_openai.py
You should see a friendly greeting from the model.
Step 2: Define Your Approval Workflow Logic
-
Map Out the Approval Criteria
For example, an expense approval workflow might require:- Amount < $500: Auto-approve
- Amount ≥ $500: Manager approval required
- Expense must have a valid receipt
- Certain categories (e.g., "Travel") may need extra scrutiny
For more real-world templates, see Prompt Engineering for Approval Workflows: Templates & Real-World Examples.
-
Create Example Input Data
{ "employee": "Jane Doe", "amount": 425.50, "category": "Travel", "receipt_attached": true, "description": "Flight to client site" } -
Decide Output Format
For auditability, use structured JSON output:{ "decision": "APPROVE", "reason": "Amount is below threshold and receipt is attached.", "escalate_to": null }
Step 3: Engineer Your Base Prompt
-
Write a Clear, Directive Prompt
You are an approval workflow assistant. Given an expense request in JSON, decide whether to APPROVE or REJECT it based on these rules: - If amount < $500 and a receipt is attached, APPROVE. - If amount ≥ $500, escalate to manager. - If no receipt, REJECT. - For "Travel" category over $300, flag for extra scrutiny. Respond ONLY in this JSON format: { "decision": "APPROVE | REJECT | ESCALATE", "reason": "[short explanation]", "escalate_to": "[manager name or null]" } -
Test the Prompt Interactively
Add this to your test script:messages = [ {"role": "system", "content": "You are an approval workflow assistant..."}, {"role": "user", "content": "Request:\n" + json.dumps(example_data, indent=2)} ] response = openai.chat.completions.create( model="gpt-3.5-turbo", messages=messages, temperature=0 ) print(response.choices[0].message.content)Screenshot Description: The terminal displays a JSON response such as
{"decision": "APPROVE", "reason": "...", "escalate_to": null}. -
Iterate on Prompt Clarity
If the model outputs unstructured text or misses a rule, clarify your instructions. For advanced strategies, see Prompt Engineering for Multi-Step Automated Data Pipelines.
Step 4: Add Context, Examples, and Guardrails
-
Add Few-Shot Examples
LLMs respond better with concrete examples:Example 1: Input: {"employee": "John Smith", "amount": 200, "category": "Meals", "receipt_attached": true} Output: {"decision": "APPROVE", "reason": "Amount is below threshold and receipt is attached.", "escalate_to": null} Example 2: Input: {"employee": "Alice Lee", "amount": 700, "category": "Travel", "receipt_attached": true} Output: {"decision": "ESCALATE", "reason": "Amount exceeds $500, escalate to manager.", "escalate_to": "Manager"} -
Explicitly Tell the Model to Output Only JSON
Add:"Respond ONLY with valid JSON in the specified format. Do not include any extra explanation." -
Set Temperature to 0
This reduces creative variance and enforces consistency:response = openai.chat.completions.create( model="gpt-3.5-turbo", messages=messages, temperature=0 ) -
Test Edge Cases
Try missing fields, borderline amounts, or ambiguous categories to see how well the prompt holds.{"employee": "Sam", "amount": 499.99, "category": "Travel", "receipt_attached": false}Screenshot Description: The terminal displays a JSON output with "decision": "REJECT" and a reason referencing the missing receipt.
Step 5: Integrate with Your Workflow Automation Tool
-
Wrap the LLM Call in a Function
def approve_expense(expense_data): messages = [ {"role": "system", "content": PROMPT_STRING}, {"role": "user", "content": "Request:\n" + json.dumps(expense_data, indent=2)} ] response = openai.chat.completions.create( model="gpt-3.5-turbo", messages=messages, temperature=0 ) return json.loads(response.choices[0].message.content) -
Expose as an API Endpoint (Optional)
WithFastAPI:from fastapi import FastAPI, Request import uvicorn app = FastAPI() @app.post("/approve") async def approve(request: Request): data = await request.json() result = approve_expense(data) return result if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8000)pip install fastapi uvicorn
python my_approval_api.py
Screenshot Description: Terminal shows
INFO: Uvicorn running on http://0.0.0.0:8000. -
Connect to Your Workflow Tool
Use a webhook or HTTP request action in Zapier, n8n, or your custom backend to POST expense data to/approveand handle the response. -
Log Decisions for Auditing
Store both the input data and the LLM's output in a database or audit log for compliance. For more on compliance and risk, see Security & Compliance Risks in Automated Approval Workflows.
Step 6: Test, Monitor, and Refine Prompt Performance
-
Batch Test with Realistic Data
Create a suite of test cases covering all rules and edge cases. Example:test_cases = [ {"employee": "Jane Doe", "amount": 425.50, "category": "Travel", "receipt_attached": True}, {"employee": "Bob", "amount": 700, "category": "Supplies", "receipt_attached": True}, {"employee": "Alice", "amount": 300, "category": "Meals", "receipt_attached": False}, ] for case in test_cases: print(approve_expense(case))Screenshot Description: Terminal output shows a list of JSON decision objects, each matching the workflow logic.
-
Monitor for Hallucinations or Format Drift
If the model ever outputs invalid JSON or strays from the format, update your prompt or add post-processing validation.For techniques to reduce hallucinations, see How to Use Prompt Engineering to Reduce AI Hallucinations in Workflow Automation.
-
Refine Rules and Prompts Over Time
As your business logic evolves, update your prompt, examples, and test cases. Consider versioning your prompts for traceability.
Common Issues & Troubleshooting
-
Model returns unstructured text instead of JSON:
- Explicitly instruct: "Output ONLY valid JSON, nothing else."
- Set
temperature=0for deterministic output. - Add more few-shot examples.
-
Incorrect or inconsistent decisions:
- Clarify ambiguous rules in your prompt.
- Test with more edge cases.
- Use more specific examples for each rule.
-
API errors (rate limits, timeouts):
- Implement retries and exponential backoff.
- Monitor your API usage and upgrade your plan if needed.
-
Security/compliance concerns:
- Never send sensitive data to third-party APIs without legal review.
- Log all decisions for auditability.
- Mask or anonymize PII where possible.
Next Steps
- Expand to Multi-Step Workflows: Add sequential approvals, conditional logic, or multi-agent review. See How to Automate Workflow Approval Loops with Custom AI Agents.
- Integrate with Business Systems: Connect your approval logic to ERP, HRIS, or procurement platforms for end-to-end automation.
- Compare LLM Providers: Test with different models (OpenAI, Azure, Hugging Face) and compare accuracy, speed, and cost. For a market overview, read The Rise of Approval Bots: Comparing Top AI Tools.
- Stay Current with Regulations: Approval automation is evolving fast. Keep up with legal and compliance updates, such as the latest US FTC guidance on automated AI approval workflows.
Generative AI prompt engineering is a powerful lever for automating complex approval workflows. With clear prompts, robust testing, and careful integration, you can unlock massive efficiency while maintaining control, auditability, and compliance. For the full landscape—including best practices, legal risks, and platform comparisons—see our Ultimate Guide to Automating Approval Workflows with AI in 2026.