[
https://issues.apache.org/jira/browse/CAMEL-23327?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18074273#comment-18074273
]
Zineb Bendhiba commented on CAMEL-23327:
----------------------------------------
After investigation, JSON Schema structured outputs cannot be handled at the
component level. The ResponseFormat with JSON Schema must be configured
directly on the ChatModel instance (e.g.,
OllamaChatModel.builder().responseFormat(...)) before passing it to the
AgentConfiguration. This is a LangChain4j design : our component only receives
an already-configured ChatModel and has no control over its response format
settings.
What I can offer is :
- Documentation on how to configure structured outputs with JSON Schema on
the ChatModel for supported providers (OpenAI, Azure OpenAI, Amazon Bedrock,
Google AI Gemini, Mistral, Ollama)
- Implement an integration test with Ollama validating that the agent
response conforms to a JSON Schema, using the camel-json-validator component in
the route as a post-processing validation step
As a future improvement, I'm considering implementing a Camel route-based
guardrail mechanism (a guardrail that delegates to a Camel route endpoint).
This would allow users to leverage existing Camel components like
json-validator as output guardrails. For example, validating the LLM response
against a JSON Schema before it reaches the next step in the route.
> Add jsonSchema parameter to camel-langchain4j-agent for structured output
> -------------------------------------------------------------------------
>
> Key: CAMEL-23327
> URL: https://issues.apache.org/jira/browse/CAMEL-23327
> Project: Camel
> Issue Type: New Feature
> Components: camel-langchain4j-agent
> Reporter: Zineb Bendhiba
> Assignee: Zineb Bendhiba
> Priority: Major
> Fix For: 4.20.0
>
>
> The camel-openai component supports a jsonSchema endpoint parameter that
> enables Structured Outputs. This guarantees the LLM response conforms to a
> provided JSON Schema, with no prompt engineering needed for output formatting.
> LangChain4j already supports the same feature through
> JsonRawSchema.from(schemaString) and the ResponseFormat API. Supported
> providers include for now Amazon Bedrock, Azure OpenAI, Google AI Gemini,
> Mistral, Ollama and OpenAI.
> The camel-langchain4j-agent component should expose a jsonSchema (String)
> endpoint parameter, consistent with camel-openai. When set, the producer
> would build the ResponseFormat using JsonRawSchema.
> The parameter should follow same pattern as camel-openai and support
> resource:classpath: for loading schema files, so the usage in YAML DSL would
> be:
>
> {code:java}
> - to:
> uri: langchain4j-agent:myAgent
> parameters:
> jsonSchema: "resource:classpath:my-schema.json"
> {code}
>
> This would allow users to share the same JSON schema file across camel-openai
> and camel-langchain4j-agent routes.
> References:
>
> * [LangChain4j Structured Outputs
> docs[|https://docs.langchain4j.dev/tutorials/structured-outputs/|https://docs.langchain4j.dev/tutorials/structured-outputs]]
> * camel-openai jsonSchema parameter (introduced in 4.18)
--
This message was sent by Atlassian Jira
(v8.20.10#820010)