> ## Documentation Index
> Fetch the complete documentation index at: https://agent-observability-docs.splunk.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Handling Ignored Instructions

> Learn how to handle ignored instructions and ensure that your AI models follow your instructions

When a model ignores instructions, it generates responses that deviate from the provided prompt structure, missing key details or adding extraneous information. This can lead to misleading, unhelpful, or non-compliant outputs.

## Setup

In this example, we'll use the `gpt-4o` model to generate a response to for a simple prompt. We'll enable the `instruction_adherence` evaluator to monitor the model's adherence to the prompt.

To calculate evaluators, you will need to configure an integration with an LLM. Visit the relevant API platform to obtain an API key, then add it using the **LLM Integrations** page in the Splunk Agent Observability UI.

```python theme={null}
import os
from splunk_ao.openai import openai
from dotenv import load_dotenv
load_dotenv()

client = openai.OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))

prompt = f"Explain the following topic succinctly: Newton's First Law"
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "system", "content": prompt}],
)
print(response.choices[0].message.content.strip())
```

### What showed up in evaluators

When we examine the Instruction Adherence evaluator, we see a score of 0.6667:

<img src="https://mintcdn.com/agent-observability-docs/0i9p_J7eAsCmqtd7/images/g2/chatbot-low-instruction-adherence-evaluator.png?fit=max&auto=format&n=0i9p_J7eAsCmqtd7&q=85&s=5625e19520df4dc585721cace2aad1a6" alt="Instruction Adherence Evaluators - Before Optimization" width="1920" height="72" data-path="images/g2/chatbot-low-instruction-adherence-evaluator.png" />

That means the model didn't fully follow the instructions in the prompt.
To understand why Splunk Agent Observability flagged this, we can review the explanation:

As shown in the dashboard above, the instruction adherence score is low, indicating that our prompt wasn't followed correctly.

<Card>
  <ResponseField name="Evaluator Explanation">
    `The instruction provided was to 'Explain the following topic succinctly:
            Newton's first law'. The response begins by defining Newton's First Law and
            provides a clear explanation of the concept of inertia. However, the
            response is lengthy and provides more detail than the word 'succinctly'
            implies. While it does effectively cover the essence of the topic, it could
            be more concise to align better with the instruction. Thus, while
            informative, the response does not fully adhere to the request for a
            succinct explanation.`
  </ResponseField>
</Card>

### What went wrong?

As the explanation indicates, the main reason the model did not follow the instructions is that the prompt is too vague. The prompt does not provide enough information about what constitutes a "succinct" explanation.

## The solution

In order to fix this, we can modify the prompt to provide more specific instructions:

<CodeGroup>
  ```python Python theme={null}
  prompt = """
    1. Explain Newton's First Law in one sentence of no more than fifteen (15)
       words.
    2. Do not add any additional sentences, examples, parentheses, bullet points,
       or further clarifications.
    3. Your answer must be exactly one sentence and must not exceed 15 words.
  """
  ```
</CodeGroup>

In this updated prompt, we gave the model more specific instructions about what constitutes a "succinct" explanation. We worded the prompt in three distinct variations to eliminate any ambiguity.

If we run the application again, we see that the model now follows the instructions more closely:

```text theme={null}
An object remains at rest or in uniform motion unless acted upon by a
net force.
```

Now, our instruction adherence evaluator jumps to 100.00%!

<img src="https://mintcdn.com/agent-observability-docs/Y4gaVgpsSUs8MBdT/images/g2/chatbot-trace-improvement.png?fit=max&auto=format&n=Y4gaVgpsSUs8MBdT&q=85&s=380abad7a20d858ea30051fc43f0d648" alt="Instruction Adherence Evaluators - After Optimization" width="1920" height="205" data-path="images/g2/chatbot-trace-improvement.png" />

As demonstrated in the evaluators dashboard above, our optimized prompt with specific, unambiguous instructions resulted in perfect adherence to our requirements. The model now produces exactly what we asked for: a concise, single-sentence explanation within the specified word limit.

By monitoring instruction adherence and iteratively improving your prompts based on the evaluators, you can ensure your AI models consistently follow instructions as intended.
