Skip to content

How to view grounding scores for an AWS Bedrock agent with guardrails enabled (contextual grounding only)?

0

Hi, I'm working with Amazon Bedrock and have the following setup:

I've created an agent using AWS Bedrock.

Later, I created a guardrail in Bedrock with only contextual grounding enabled.

For invoking the agent, I'm using the invoke_agent method via boto3 from a Lambda function.

I tested the guardrail separately using the apply_guardrail method (also via boto3), and I can see the grounding scores in the logs.

Issue: When I invoke the agent using invoke_agent, the response doesn't include the grounding scores (which I can see when calling apply_guardrail directly).

Question: Is there a way to retrieve grounding scores when invoking a Bedrock agent that has a guardrail with contextual grounding enabled? Do I need to enable any specific settings or pass any parameters in the invoke_agent call to get this metadata?

Any help or guidance would be appreciated. Thanks!

2 Answers
0

To view grounding scores for an AWS Bedrock agent with guardrails enabled (specifically for contextual grounding), you need to make some adjustments to your approach. Here's what you can do:

  1. Enable tracing: When invoking the agent, you need to enable tracing to get detailed information about the guardrail evaluations, including grounding scores. You can do this by setting the 'trace' parameter to 'ENABLED_FULL' in your invoke_agent call.

  2. Check the response: With tracing enabled, the response from invoke_agent should include a 'trace' field. This field will contain detailed information about the guardrail evaluations, including the contextual grounding scores.

  3. Examine the trace: In the trace, look for the 'guardrailEvaluations' section. Within this, you should find information about the contextual grounding check, including the grounding and relevance scores.

  4. Parse the scores: The scores will be provided as values between 0 and 1. A higher score indicates better grounding or relevance.

It's important to note that the contextual grounding check is only performed on the output, not on the prompt. If you've marked specific content blocks with the 'guard_content' qualifier, the contextual grounding check will focus on those blocks along with the grounding source and query.

If you're not seeing the scores even with tracing enabled, double-check that your guardrail is correctly associated with the agent and that the contextual grounding check is indeed enabled in your guardrail configuration.

Remember, by default, only detected content (content that breaches your guardrail configurations) is returned in the response. If you want to see all evaluations, including those that didn't trigger the guardrail, make sure you've set the output scope to 'FULL' in your guardrail configuration.

If you're still not seeing the scores, you might want to review your IAM permissions to ensure you have the necessary access to view detailed guardrail information.
Sources
Use the ApplyGuardrail API in your application - Amazon Bedrock
Use contextual grounding check to filter hallucinations in responses - Amazon Bedrock
GuardrailContextualGroundingFilter - Amazon Bedrock

answered a year ago

0

Even with enableTrace=True, the response from invoke_agent does not contain any contextual grounding scores (like groundingScore, relevanceScore, etc.).

Instead, the guardrailTrace section only contains:

contentPolicy

sensitiveInformationPolicy

topicPolicy

wordPolicy

There's no mention of contextualGroundingPolicy or anything related to grounding/relevance scoring.

Additional Observation: The boto3 documentation for invoke_agent https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-agent-runtime/client/invoke_agent.html#invoke-agent also does not show any fields or structure related to contextual grounding in the response format.

This raises two questions:

1.Is contextual grounding currently supported in invoke_agent traces at all?

2.If so, is there any special configuration required to surface these scores?

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.