Jiří Ondrušek created CAMEL-27912:
-------------------------------------

             Summary: camel-ai-guardrail: use Camel routes as LangChain4j 
guardrails
                 Key: CAMEL-27912
                 URL: https://issues.apache.org/jira/browse/CAMEL-27912
             Project: Camel
          Issue Type: New Feature
          Components: camel-ai
            Reporter: Jiří Ondrušek
            Assignee: Jiří Ondrušek


h3. Problem
LangChain4j guardrails are Java classes. In Camel they can only be attached by 
class (`AgentConfiguration.withInputGuardrailClasses` / 
`withOutputGuardrailClasses`); there is no way to write a guardrail as a route, 
in the Java DSL or in YAML.

h3. Proposal
A new consumer component 
`ai-guardrail:<name>?type=input|output&tags=..&order=..&timeout=..`: the route 
is the guardrail, selected by tag like `ai-tool`. Two adapter classes in 
`camel-langchain4j-agent-api` (`CamelRouteInputGuardrail`, 
`CamelRouteOutputGuardrail`) run the routes for LangChain4j.
* The body is the text to check; type, name, memory id, user message and 
invocation parameters are exchange properties.
* Outcome header `CamelAiGuardrailOutcome`: none or `success` passes, `rewrite` 
(explicit only, body = new text), `failure`, `fatal`.
* Fail closed: a route exception, timeout, rejection, blank or unknown outcome, 
rollback-only exchange, or a handled exception without an explicit outcome is 
fatal. A tag needs a route of the called type; a stopped route rejects.
* The documentation lists the pitfalls and the tool-result prompt-injection 
risk (tool-level guardrails are out of scope).

h3. Follow-ups
A `guardrailTags` option on `langchain4j-agent`, retry and reprompt outcomes, 
and a Camel Quarkus bridge for `@RegisterAiService`.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to