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
CI / Shell Format Check (push) Waiting to run
CI / Check Ruby (3.4) (push) Waiting to run
CI / CI Config (push) Waiting to run
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Blocked by required conditions
CI / Build on Node ${{ matrix.node }} (push) Blocked by required conditions
CI / Style Check (push) Waiting to run
CI / Generate Assets (push) Waiting to run
CI / Check Python (3.14) (push) Waiting to run
CI / Check Python (3.9) (push) Waiting to run
CI / Build Docs (push) Waiting to run
CI / Code Scan Action (push) Waiting to run
CI / Site tests (push) Waiting to run
CI / webui tests (push) Waiting to run
CI / Run Integration Tests (push) Waiting to run
CI / Run Smoke Tests (push) Waiting to run
CI / Go Tests (push) Waiting to run
CI / Share Test (push) Waiting to run
CI / Redteam (Production API) (push) Waiting to run
CI / Redteam (Staging API) (push) Waiting to run
CI / GitHub Actions Lint (push) Waiting to run
CI / Check Ruby (3.0) (push) Waiting to run
release-please / release-please (push) Waiting to run
release-please / build (push) Blocked by required conditions
release-please / publish-npm (push) Blocked by required conditions
release-please / publish-npm-backfill (push) Waiting to run
release-please / docker (push) Blocked by required conditions
release-please / publish-code-scan-action (push) Blocked by required conditions
release-please / attest-code-scan-action (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:24:08 +08:00
..

config-structured-outputs (Multi-Provider Structured Outputs)

You can run this example with:

npx promptfoo@latest init --example config-structured-outputs
cd config-structured-outputs

This example demonstrates how to enforce structured JSON outputs using schema validation across multiple AI providers:

  • OpenAI - using response_format with json_schema
  • Azure OpenAI - using response_format with json_schema
  • Anthropic - using output_format with json_schema

The example includes two prompt configurations for solving quirky math problems:

  • One that requires step-by-step problem solving (with steps array)
  • One that only requires the final answer (without steps array)

Environment Variables

This example requires at least one of the following API keys:

  • OPENAI_API_KEY - Your OpenAI API key for testing with GPT models
  • ANTHROPIC_API_KEY - Your Anthropic API key for testing with Claude models
  • For Azure OpenAI: See Azure OpenAI provider docs for required credentials

You can set these in a .env file or directly in your environment:

export OPENAI_API_KEY=your_api_key_here
export ANTHROPIC_API_KEY=your_api_key_here

Provider Differences

OpenAI/Azure Format

OpenAI and Azure use response_format at the prompt level:

prompts:
  - raw: 'Your prompt here'
    config:
      response_format:
        type: json_schema
        json_schema:
          name: schema_name
          strict: true
          schema:
            # Your schema here

Anthropic Format

Anthropic uses output_format at the provider level:

providers:
  - id: anthropic:messages:claude-sonnet-4-6
    config:
      output_format:
        type: json_schema
        schema:
          # Your schema here (no nested json_schema object)

Getting Started

  1. Review and customize promptfooconfig.yaml as needed

  2. Remove any providers you don't have API keys for

  3. Run the evaluation:

    promptfoo eval
    
  4. View the results:

    promptfoo view
    

What You'll Learn

  • How to enforce JSON schemas across different providers
  • The syntax differences between OpenAI and Anthropic structured outputs
  • How to validate that responses are always valid JSON objects
  • How to require specific fields and types in LLM responses

Learn More