Skip to content

Add support for native GenAI response schema instead of instruction injection #4463

@angfal

Description

@angfal

Expected Behavior

SpringAI should leverage the native response schema mechanism provided by the underlying GenAI model when a response class is provided via .entity(...).

Example:

ResponseSchema response = ChatClient.builder(chatModel)
    .build()
    .prompt(prompt)
    .call()
    .entity(ResponseSchema.class);

Internally, SpringAI should translate this into a structured call without injecting additional instructions into the last UserMessage.

Current Behavior

Currently, SpringAI appends additional instructions to the last UserMessage to guide the LLM response formatting when .entity(...) is used.

This breaks the intended use of GenAI-native response schema features, and may reduce reliability or introduce hallucinations, especially when dealing with complex schemas.

Context

This affects use cases where strict adherence to schema is expected or required - e.g., structured output for downstream automation or parsing.

Using injected instructions is less robust and prone to failures with non-trivial or deeply nested schemas.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions