Templates / Automatically optimize AI prompts with OpenAI using OPRO & DSPy methodology

Automatically optimize AI prompts with OpenAI using OPRO & DSPy methodology

Ready for 3.0

by Shun Nakayama ✓ · 542 views · created 2025-12-04 · Engineering, AI Summarization

Ready for 3.0. This template uses no nodes that n8n 3.0 removes. No removed nodes, versions or helpers found. Static check, last run 2026-12-01.

📬 Weekly n8n 3.0 breakage alerts, free

What this workflow does

This AI workflow has 12 nodes and runs manually, when you click “Execute workflow”. Along the way it connects OpenAI Chat Model.

How it runs

Trigger: Manually, when you click “Execute workflow”.

  1. Define Initial Prompt & Test Data (Edit Fields (Set)): sets 3 fields: initial_prompt, test_input, ground_truth
  2. Manage Loop & State (Code): runs custom JavaScript code
  3. Check Loop Condition (If): checks a condition and branches into true / false
  4. AI Response Generator (AI Agent): runs an AI agent, with model: OpenAI Chat Model
  5. AI Response Evaluator (AI Agent): runs an AI agent, with model: OpenAI Chat Model; output parser: Evaluator Output Parser
  6. AI Prompt Optimizer (AI Agent): runs an AI agent, with model: OpenAI Chat Model; output parser: Optimizer Output Parser
  7. Update Prompt & Loop Count (Edit Fields (Set)): sets 3 fields: next_loop_count, improved_prompt, change_log

Services it uses

OpenAI Chat Model

Before you upgrade to n8n 3.0

Nothing in this workflow is removed in n8n 3.0, so it should import and run after the upgrade.

Nodes used (8)

From the author

This workflow implements cutting-edge concepts from Google DeepMind's OPRO (Optimization by PROmpting) and Stanford's DSPy to automatically refine AI prompts. It iteratively generates, evaluates, and optimizes responses against a ground truth, allowing you to…

Excerpt from Shun Nakayama's description on n8n.io.

View the original on n8n.io → Check your own copy

Get the weekly “what broke” email

New templates, newly broken ones, and n8n release changes. One short email a week.

Form not loading? Subscribe here.