simulateConstrainedGeneration function

GenerateMiddlewareRef<void> simulateConstrainedGeneration()

Puts a requested output schema in the prompt instead of sending it to the model as a native constraint.

For a model or provider without native constrained generation:

final response = await ai.generate(
  model: someModel,
  prompt: 'Describe a cat',
  outputSchema: Cat.$schema,
  use: [simulateConstrainedGeneration()],
);

Opt-in: core never adds it, whatever the model declares under supports.constrained. See SimulateConstrainedGenerationMiddleware for exactly what it changes.

Implementation

GenerateMiddlewareRef<void> simulateConstrainedGeneration() =>
    simulateConstrainedGenerationDef();