Files
wehub-resource-sync 0d3cb498a3
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:24:08 +08:00

3.2 KiB

title, sidebar_position, sidebar_label, description
title sidebar_position sidebar_label description
Prompt Optimization 11 Prompt optimization Optimize one prompt against one provider with promptfoo. Learn how candidate search, validation splits, target selection, and result review work safely.

Prompt Optimization

promptfoo optimize improves one configured prompt against one configured provider using the tests already defined in your eval config. It runs a baseline eval, asks an optimizer model for revised prompt candidates using observed failures and prior scores, evaluates those candidates, and prints the strongest prompt it found.

Use prompt optimization when you already have:

  • A prompt that needs measurable improvement
  • A provider you want to tune that prompt for
  • Test cases and assertions that represent the behavior you want

Basic workflow

Start with a normal eval config:

providers:
  - openai:gpt-4.1-mini

prompts:
  - |-
    Answer the user's support question.
    Be concise.

    Question: {{question}}

tests:
  - vars:
      question: How do I reset my password?
    assert:
      - type: contains
        value: reset
  - vars:
      question: Can I cancel my subscription today?
    assert:
      - type: llm-rubric
        value: The answer clearly explains the cancellation path.

Then run:

promptfoo optimize

When -c is omitted, promptfoo loads promptfooconfig.yaml from the current directory.

Choose the prompt and provider

Optimization targets exactly one resolved prompt/provider pair. By default, promptfoo uses prompt index 0 and provider index 0.

promptfoo optimize --prompt-index 1 --provider-index 0

These are zero-based indices after the config is resolved. This keeps the optimization objective narrow: one prompt is being tuned for one provider, against one test suite.

The selected provider is the target being optimized. Candidate prompt rewrites are generated separately by Promptfoo's default suggestions provider.

Use a validation split

By default, optimization searches against the full eval set. That is fast, but it can overfit to the configured tests.

Use --validation-split to hold out part of the test set for candidate selection:

promptfoo optimize --validation-split 0.2

With 0.2, promptfoo searches on roughly 80% of the configured tests and judges candidate adoption on the held-out 20%. The split is optional and may be any value greater than 0 and less than or equal to 0.5.

:::note Validation splitting requires explicit tests. If your config uses scenarios, expand them into explicit test cases before passing --validation-split. :::

Practical guidance

Prompt optimization is only as good as the eval it searches against. Before optimizing:

  • Make sure the tests represent the behavior you care about
  • Prefer assertions that distinguish materially better outputs from merely different outputs
  • Use a validation split when the test set is large enough to support one
  • Tune one prompt/provider pair at a time, then compare results deliberately

For command flags and concise syntax, see the promptfoo optimize CLI reference.