Skip to content

Add native structured output support for Mistral AI #5043

@KyleKreuter

Description

@KyleKreuter

Expected Behavior

Users should be able to use Spring AI's native structured output integration with Mistral AI:

ChatClient.create(mistralChatModel)
    .prompt("Generate a movie review")
    .advisors(AdvisorParams.ENABLE_NATIVE_STRUCTURED_OUTPUT)
    .call()
    .entity(MovieReview.class);

This requires MistralAiChatOptions to implement StructuredOutputChatOptions, similar to OpenAiChatOptions.

Current Behavior

MistralAiChatOptions only implements ToolCallingChatOptions:

public class MistralAiChatOptions implements ToolCallingChatOptions { }

This prevents native structured output integration. When using .entity(Class), the check in ChatModelCallAdvisor fails:

chatClientRequest.prompt().getOptions() instanceof StructuredOutputChatOptions
// → false for MistralAI, falls back to prompt-based instructions

Users must manually generate and inject the JSON schema as a workaround.

Context

  • Mistral AI's API supports structured outputs with JSON schema

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions