Prompt Optimizer

Improve a base prompt for either LLM-style or agent-style downstream use.

What this block does

The Prompt Optimizer block takes msg.payload.base_prompt, sends it to the selected provider, and returns an improved prompt directly in msg.payload.

The UI controls two important settings:

  • provider
  • optimize_for: llm or agent

Inputs

Required in msg.payload

  • base_prompt (string)

Provider-specific fields

The block forwards your payload to the prompt optimization service. Include the fields required by the provider you selected in the UI.

  • OpenAI
    • api_key
    • optional: model_name
    • optional: model_config
  • Azure OpenAI
    • api_key
    • azure_endpoint
    • api_version
    • optional: model_name
    • optional: model_config
  • Vertex
    • project
    • location
    • service_account_info
    • optional: model_name
    • optional: model_config
  • Gemini
    • api_key
    • optional: model_name
    • optional: model_config
  • Antropic
    • api_key
    • optional: model_name
    • optional: model_config

Output

On success, the block returns the optimized result directly as msg.payload.

Typical keys are:

  • optimized_prompt (string)
  • provider (string)
  • model_name (string)
  • latency_ms (number)
  • usage (object)

On failure, the block returns an error shape directly in msg.payload, typically:

  • error (boolean)
  • message (string)

Example

Input (msg.payload)

{
  "base_prompt": "Turn these release notes into a clean 5-bullet summary.",
  "api_key": "sk-...",
  "model_name": "gpt-4o-mini",
  "model_config": {
    "temperature": 0.2,
    "max_tokens": 256
  }
}

Output (msg.payload)

{
  "optimized_prompt": "You are a concise technical writer. Convert the release notes below into exactly 5 clear bullet points. Do not add facts that are not present in the notes.",
  "provider": "openai",
  "model_name": "gpt-4o-mini",
  "latency_ms": 430,
  "usage": {
    "prompt_tokens": 120,
    "completion_tokens": 220,
    "total_tokens": 340
  }
}

Limitations

  • The block improves prompt text only; it does not execute your downstream LLM or agent workflow.
  • base_prompt must be a string.
  • Unsupported provider values return an error.

Common mistakes

  • Missing msg.payload.base_prompt.
  • Sending base_prompt as a non-string value.
  • Forgetting provider-specific credentials or connection fields.
  • Expecting the result under msg.payload.output; the optimized response is sent directly in msg.payload.