Skip to content

CAMEL-23642: camel-langchain4j-agent - support jsonSchema endpoint pr…#23793

Open
zbendhiba wants to merge 1 commit into
apache:mainfrom
zbendhiba:CAMEL-23642-json-schema
Open

CAMEL-23642: camel-langchain4j-agent - support jsonSchema endpoint pr…#23793
zbendhiba wants to merge 1 commit into
apache:mainfrom
zbendhiba:CAMEL-23642-json-schema

Conversation

@zbendhiba
Copy link
Copy Markdown
Contributor

…operty for structured outputs

Add a jsonSchema URI property to the langchain4j-agent component that loads a JSON schema (classpath, file, or inline) and applies it as a ResponseFormat on the internal AIService. This works only in agentConfiguration mode where Camel creates the agent internally.

Summary

  • Add a jsonSchema endpoint property to the camel-langchain4j-agent component for structured LLM outputs
  • Supports classpath resources, file paths, and inline JSON — same resolution pattern as camel-openai

Example usage

from("direct:extract")
    .to("langchain4j-agent:test?agentConfiguration=#myConfig"
        + "&jsonSchema=classpath:person-schema.json")

Test plan

  • Integration test with classpath schema (classpath:person-schema.json)
  • Integration test with inline schema (RAW(...))
  • Integration test with file schema (file:...)
  • All three routes validate responses with json-validator against the schema

…operty for structured outputs

Add a jsonSchema URI property to the langchain4j-agent component that loads
a JSON schema (classpath, file, or inline) and applies it as a ResponseFormat
on the internal AIService. This works only in agentConfiguration mode where
Camel creates the agent internally.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zbendhiba zbendhiba requested review from Croway and orpiske June 5, 2026 13:53
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

🧪 CI tested the following changed modules:

  • catalog/camel-catalog
  • components/camel-ai/camel-langchain4j-agent-api
  • components/camel-ai/camel-langchain4j-agent
  • dsl/camel-componentdsl
  • dsl/camel-endpointdsl

⚠️ Some tests are disabled on GitHub Actions (@DisabledIfSystemProperty(named = "ci.env.name")) and require manual verification:

  • components/camel-ai/camel-langchain4j-agent: 15 test(s) disabled on GitHub Actions
All tested modules (12 modules)
  • Camel :: AI :: LangChain4j :: Agent
  • Camel :: AI :: LangChain4j :: Agent :: API
  • Camel :: Catalog :: Camel Catalog
  • Camel :: Component DSL
  • Camel :: Endpoint DSL
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: Launcher :: Container
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin

⚙️ View full build and test results

String resolved = endpoint.getCamelContext().resolvePropertyPlaceholders(jsonSchema);

String content = resolveResourceContent(resolved);
if (content != null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happen if a non existent json file is passed? ala jsonSchema=non-existent.json.

Maybe overkill, what happen if the passed file is not a json?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Croway Good catch! I'll investigate proper error handling for those edge cases next Monday and address them in a follow-up. If one of the two concerns turns out to be overkill, I'll open a separate issue for it instead.

Copy link
Copy Markdown
Contributor

@davsclaus davsclaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well-structured feature that significantly simplifies structured output configuration — from manual ResponseFormat + ChatModel wiring to just &jsonSchema=classpath:person-schema.json. Resource resolution via ResourceHelper supports classpath, file, and inline (RAW(...)) consistently with camel-openai. The chatRequestTransformer workaround is documented with a CAMEL-23695 reference. Three integration tests cover all resolution modes with json-validator validation. CI is green.

This review does not replace specialized AI review tools (CodeRabbit, Sourcery) or static analysis (SonarCloud).

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants