Back to Promptfoo

openai-structured-output (OpenAI Structured Output Example)

examples/openai-structured-output/README.md

0.121.91.6 KB
Original Source

openai-structured-output (OpenAI Structured Output Example)

This example demonstrates how to define JSON schemas for OpenAI's Structured Output feature in two different ways:

  1. Inline schema definition - defined directly in the config file
  2. External schema file - stored in a separate JSON or YAML file and referenced with file://

Usage

You can run this example with:

bash
npx promptfoo@latest init --example openai-structured-output
cd openai-structured-output

Environment Variables

This example requires:

  • OPENAI_API_KEY - Your OpenAI API key

Example Structure

This example includes several files that demonstrate different approaches:

FileDescription
promptfooconfig.chat.yamlChat API config using both inline and external schemas
promptfooconfig.responses.yamlResponses API config using both inline and external schemas
schema.responses.yamlExternal schema file for Responses API
schema.chat.jsonExternal schema file for Chat API

Running the Example

bash
cd openai-structured-output
promptfoo eval -c promptfooconfig.chat.yaml
promptfoo eval -c promptfooconfig.responses.yaml

Additional Resources