Repository: promptfoo/promptfoo
Issue: Dynamic generationConfig for response schema
Root cause: Documentation Deficiency

Problem: The response schema for LLM responses is created dynamically in the TypeScript code of my application like so:

```typescript
const stream = await llmClient.chat.completions.create({
  model: CONVERSATION_MODEL_NAME,
  messages: [
    { role: 'system', content: finalSystemPrompt },
    { role: 'user', content: userPrompt },
  ],
  response_format: zodResponseFormat(
    DynamicConversationSchema,
    'conversation_response',
  ),
  stream: true,
  stream_options: {
    include_usage: true,
  },
})
```

Then, setting up evaluations with promptfoo for this LLM query, I need to also specify the same JSON schema so that promptfoo is calling the provider with the right configuration:

```
providers:
  - id: google:gemini-2.5-flash
    config:
      maxOutputTokens: 8192
      generationConfig:
        response_mime_type: 'application/json'
        response_schema:
          type: object
          properties:
            scenario:
              type: string
            preamble:
              type: string
            targetLanguage:
              type: string
            understoodLanguage:
              type: string
            difficulty:
              type: string
            formality:
              type: string
            tags:
              type: array
              items:
                type: string
            ...
```

Maintaining two copies of this schema is not ideal. I would like to be able to use the same zod schema as my application code does, by promptfoo being able to generate the schema dynamically through TypeScript.

It's not well documented, but it seems like you can write promptfoo configs in TypeScript.

This seems to work:


```ts
// promptfooconfig.ts
import type { UnifiedConfig } from 'promptfoo'
import { zodResponseFormat } from 'openai/helpers/zod.mjs'
import { createConversationSchema } from '../src/llm/conversation-schema.js'

const schema = createConversationSchema('english')
const rawResponseFormat = zodResponseFormat(schema, 'conversation_response')
const cleanedSchema = cleanSchemaForGemini(rawResponseFormat.json_schema.schema)

function cleanSchemaForGemini(schema: any): any {
  if (typeof schema !== 'object' || schema === null) return schema

  const cleaned = { ...schema }

  // Remove properties that Gemini doesn't support
  delete cleaned.additionalProperties
  delete cleaned.$schema

  // Recursively clean nested objects
  if (cleaned.properties) {
    cleaned.properties = Object.fromEntries(
      Object.entries(cleaned.properties).map(([key, value]) => [
        key,
        cleanSchemaForGemini(value),
      ]),
    )
  }

  if (cleaned.items) {
    cleaned.items = cleanSchemaForGemini(cleaned.items)
  }

  return cleaned
}

const config: UnifiedConfig = {
  prompts: ['file://../src/llm/prompts/conversation-generation.ts'],
  providers: [
    {
      id: 'google:gemini-2.5-flash-lite-preview-06-17',
      config: {
        generationConfig: {
          response_mime_type: 'application/json',
          response_schema: cleanedSchema,
        },
      },
    },
  ],

  outputPath: './promptfoo-results.json',
}

export default config

```

```
cd promptfoo && NODE_OPTIONS=\"--import tsx\" promptfoo eval -c promptfooconfig.ts
```

It looks like commit 529cf45 was referenced here as resolving this issue (“docs: add TypeScript configuration support documentation and dynamic schema example”), but I wasn’t able to find it in the public repo or a merged PR on main.
Just checking whether that change might live in another repo (like the docs site) or a private/staging branch.
Tagging @mldangelo in case the dynamic schema docs have already shipped and this can be closed.

The documentation and example for TypeScript configuration with dynamic schema generation has been prepared in PR #6171. 

This PR includes:
- Complete working example showing how to reuse Zod schemas from your application code
- Documentation on TypeScript configuration in the modular configs guide
- Helper functions for adapting schemas between different providers (OpenAI/Gemini)

The example demonstrates exactly what @raine showed in the original issue - using the same schema definition in both your application and promptfoo tests, avoiding duplication.

You can try it out once the PR is merged with:
```bash
npx promptfoo@latest init --example ts-config
cd ts-config
npm install
NODE_OPTIONS="--import tsx" promptfoo eval -c promptfooconfig-with-schema.ts
```

@iitslamaa The commit referenced earlier (529cf45) was on a staging branch and has now been incorporated into this PR for public release.