Skip to main content
In the log to Splunk Agent Observability guide, you logged your first trace to Splunk Agent Observability. In this guide, you will evaluate the response from the LLM using the context adherence evaluator, then improve the prompt, and re-evaluate your application.

Configure an LLM integration

To evaluate an LLM application, you need to set up an LLM integration for the LLM that will be used as a judge.
1

Navigate to the LLM Integrations page

In the Splunk Agent Observability UI, navigate to the LLM Integrations page by selecting your user profile in the upper-right corner and then selecting Integrations.The user menu
2

Add an integration

Locate the LLM provider you are using (or specify a custom integration), then select the +Add Integration button.LLM provider options
3

Add settings

Specify settings for your integration (such as an API key), then select Save changes.

Log a trace with an evaluator

1

Enable the context adherence evaluator on your Agent Stream

To evaluate the Agent Stream against context adherence, you need to turn this on for your Agent Stream.Add the following import statements to the top of your app file:
Next add the following code to your app file. If you are using Python, add this after the call to splunk_ao_context.init().
This code will enable the context adherence evaluator for your Agent Stream, and this evaluator will then be calculated for all LLM spans that are logged.
2

Run your application

Now that you have evaluators turned on for your Agent Stream, re-run your application to generate another trace. This time the context adherence evaluator will be calculated.
3

Open the Agent Stream in the Splunk Agent Observability UI

In the Splunk Agent Observability UI, select your project, then select the Agent Stream.
4

Select the Traces tab

You can see the trace that was just logged in the Traces tab. The context adherence evaluator will be calculated, showing low score.A trip-planning trace with a low context adherence score
5

Get more information on the evaluation

Select the trace, then select the LLM span to drill down for more information.The trace details with an explanation of the evaluator
This shows a common problem with an AI application: the LLM does not have enough relevant context to produce a useful, personalized response. The request asks the model to plan a trip but does not provide a destination, dates, budget, or traveler preferences. As a result, the model can only give generic advice, ask for more information, or make unsupported assumptions. Let’s fix this by providing relevant traveler information as context, then confirm the improvement with a higher context adherence score.

Improve your application

To improve the context adherence score, provide the LLM with relevant traveler information, such as the destination, trip length, budget, and interests.
1

Add relevant context to your system prompt

To improve context adherence, add the traveler’s requirements and preferences to the system prompt. This is similar to providing an application with information retrieved from a RAG system.Update your code, replacing the existing system prompt with the following:
2

Run your application

Run your application again to log a new trace.
3

View the results in your terminal

The response should now provide a personalized trip plan based on the supplied traveler information. For example:
The exact response might differ depending on the model and when you run the application, but it should use the supplied destination, trip length, budget, lodging preference, and interests.
4

Check the new trace

A new trace will have been logged. This time, the context adherence score should be higher because the trip plan is grounded in the traveler information supplied in the system prompt. Select the trace to see more details.A trip-planning trace with a higher context adherence score
🎉 Congratulations, you have evaluated a trace, and used the results of the evaluation to improve your AI application.

Next steps

Sample projects

Learn how to get started with the Splunk Agent Observability sample projects that are included in every new account.

Integrate with third-party frameworks

Learn about the Splunk Agent Observability integrations with third-party SDKs to automatically log your applications

Cookbooks

Cookbooks

Learn how to perform common tasks with Splunk Agent Observability, work with third-party integrations, and use evaluations to solve AI problems

SDK reference

Python SDK Reference

The Splunk Agent Observability Python SDK reference.