Optimize prompt (iterative)
optimize_prompt_via_apiIteratively rewrite a prompt with template-based rounds, applying requirements while checking and repairing LangGPT structure, dangling references, and lost placeholders.
Instructions
Iteratively rewrite a prompt with the built-in template library (see list_templates): round 1 optimizes with a strategy template (default: langgpt-strict for system prompts, user-basic for user prompts); rounds 2..N apply your requirements with the iterate template, which sees both the original draft and the latest version. Every round is checked for LangGPT structure, dangling and lost {{placeholders}}, which are repaired automatically. Cost: 1 API call per round (+1 repair if needed). Uses a prompt-optimizer Docker deployment instead only if PO_BASE_URL is configured and PO_BACKEND allows it. For score-driven optimization with test cases, use auto_optimize_prompt.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mode | No | system = role/system prompt; user = a single one-off request | system |
| prompt | Yes | Draft prompt to optimize | |
| rounds | No | 1 = optimize only; each extra round is an iterate pass | |
| backend | No | Override PO_BACKEND for this call | |
| template | No | Optimize template id: langgpt-strict | general | output-format | analytical | user-basic | user-professional | user-planning | custom id | |
| autoRepair | No | ||
| showHistory | No | ||
| requirements | No | What the iterate rounds should change, e.g. 'reply as a Markdown table; max 200 words' | |
| enforceLangGPT | No | Validate & repair LangGPT structure (default: true for system mode) | |
| iterateTemplate | No | Iterate template id (default iterate) |