Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance output message when output guardrails fail #1199

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

edeandrea
Copy link
Collaborator

@edeandrea edeandrea commented Jan 7, 2025

Enhance the message shown to the user when output guardrails fail. If the user has multiple guardrails the current message doesn't at all indicate which guardrail failed. This is what they see:

io.quarkiverse.langchain4j.runtime.aiservice.GuardrailException: Output validation failed. The guardrails have reached the maximum number of retries

	at io.quarkiverse.langchain4j.runtime.aiservice.GuardrailsSupport.invokeOutputGuardrails(GuardrailsSupport.java:109)
	at io.quarkiverse.langchain4j.runtime.aiservice.AiServiceMethodImplementationSupport.doImplement(AiServiceMethodImplementationSupport.java:420)
	at io.quarkiverse.langchain4j.runtime.aiservice.AiServiceMethodImplementationSupport.implement(AiServiceMethodImplementationSupport.java:138)
	at io.quarkiverse.langchain4j.runtime.aiservice.MethodImplementationSupportProducer$1$1.apply(MethodImplementationSupportProducer.java:31)
	at io.quarkiverse.langchain4j.runtime.aiservice.MethodImplementationSupportProducer$1$1.apply(MethodImplementationSupportProducer.java:28)
	at io.quarkiverse.langchain4j.runtime.aiservice.MetricsCountedWrapper.wrap(MetricsCountedWrapper.java:22)
	at io.quarkiverse.langchain4j.runtime.aiservice.MethodImplementationSupportProducer$1$2.apply(MethodImplementationSupportProducer.java:40)
	at io.quarkiverse.langchain4j.runtime.aiservice.MethodImplementationSupportProducer$1$2.apply(MethodImplementationSupportProducer.java:37)
	at io.quarkiverse.langchain4j.runtime.aiservice.MetricsTimedWrapper$2.get(MetricsTimedWrapper.java:42)
	at io.micrometer.core.instrument.composite.CompositeTimer.record(CompositeTimer.java:69)
	at io.quarkiverse.langchain4j.runtime.aiservice.MetricsTimedWrapper.wrap(MetricsTimedWrapper.java:39)
	at io.quarkiverse.langchain4j.runtime.aiservice.MethodImplementationSupportProducer$1$2.apply(MethodImplementationSupportProducer.java:40)
	at io.quarkiverse.langchain4j.runtime.aiservice.MethodImplementationSupportProducer$1$2.apply(MethodImplementationSupportProducer.java:37)
	at io.quarkiverse.langchain4j.runtime.aiservice.SpanWrapper.wrap(SpanWrapper.java:32)
	at io.quarkiverse.langchain4j.runtime.aiservice.MethodImplementationSupportProducer$1$2.apply(MethodImplementationSupportProducer.java:40)
	at io.quarkiverse.langchain4j.runtime.aiservice.MethodImplementationSupportProducer$1$2.apply(MethodImplementationSupportProducer.java:37)
	at io.quarkiverse.langchain4j.runtime.aiservice.MethodImplementationSupportProducer$1.implement(MethodImplementationSupportProducer.java:46)
	at org.ericoleg.ndnp.ai.GenerateEmailService$$QuarkusImpl.generateEmail(Unknown Source)
	at org.ericoleg.ndnp.ai.GenerateEmailService$$QuarkusImpl_ClientProxy.generateEmail(Unknown Source)
	at org.ericoleg.ndnp.ai.NotificationService.sendEmail(NotificationService.java:78)
	at java.base/java.util.Optional.map(Optional.java:260)
	at org.ericoleg.ndnp.ai.NotificationService.updateStatus(NotificationService.java:57)
	at org.ericoleg.ndnp.ai.NotificationService.lambda$updateClaimStatus$1(NotificationService.java:50)
	at java.base/java.util.Optional.map(Optional.java:260)
	at org.ericoleg.ndnp.ai.NotificationService.updateClaimStatus(NotificationService.java:50)
	at org.ericoleg.ndnp.ai.NotificationService_Subclass.updateClaimStatus$$superforward(Unknown Source)
	at org.ericoleg.ndnp.ai.NotificationService_Subclass$$function$$1.apply(Unknown Source)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:73)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:62)
	at io.quarkus.opentelemetry.runtime.tracing.cdi.WithSpanInterceptor.span(WithSpanInterceptor.java:147)
	at io.quarkus.opentelemetry.runtime.tracing.cdi.WithSpanInterceptor_Bean.intercept(Unknown Source)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:30)
	at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:27)
	at org.ericoleg.ndnp.ai.NotificationService_Subclass.updateClaimStatus(Unknown Source)
	at org.ericoleg.ndnp.ai.NotificationService_ClientProxy.updateClaimStatus(Unknown Source)
	at org.ericoleg.ndnp.ai.NotificationServiceTests.emailSendsWhenUserExists(NotificationServiceTests.java:53)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:967)
	at io.quarkus.test.junit.QuarkusTestExtension.interceptTestMethod(QuarkusTestExtension.java:817)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

@edeandrea edeandrea requested a review from a team as a code owner January 7, 2025 18:19
Copy link
Collaborator

@geoand geoand left a comment

Choose a reason for hiding this comment

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

Why people love optionals and streams is beyond me...

@edeandrea
Copy link
Collaborator Author

Why people love optionals and streams is beyond me...

I find it much easier to read than having to null check, loop, only to transform a collection of objects into something else.

@geoand
Copy link
Collaborator

geoand commented Jan 7, 2025

I guess it qualifies as clean code or something...

Copy link

quarkus-bot bot commented Jan 7, 2025

Status for workflow Build (on pull request)

This is the status report for running Build (on pull request) on commit 577ca23.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

@geoand geoand merged commit 9314bcc into quarkiverse:main Jan 7, 2025
70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants