> ## Documentation Index
> Fetch the complete documentation index at: https://docs.galileo.ai/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` metric to monitor the model's adherence to the prompt.

To calculate metrics, 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 [integrations page](https://app.galileo.ai/settings/integrations) in the Galileo Console.

```python theme={null}
import os
from galileo.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 metrics

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

<img src="https://mintcdn.com/v2galileo/Pkd00P_wsNrDK5pj/images/g2/chatbot-low-instruction-adherence-metric.png?fit=max&auto=format&n=Pkd00P_wsNrDK5pj&q=85&s=10cb86c1544677e3e444acd97748cb12" alt="Instruction Adherence Metrics - Before Optimization" width="1920" height="72" data-path="images/g2/chatbot-low-instruction-adherence-metric.png" />

That means the model didn't fully follow the instructions in the prompt.
To understand why Galileo 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="Metric 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.
  """
  ```

  ```typescript TypeScript theme={null}
  const 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 metric jumps to 100.00%!

<img src="https://mintcdn.com/v2galileo/Pkd00P_wsNrDK5pj/images/g2/chatbot-trace-improvement.png?fit=max&auto=format&n=Pkd00P_wsNrDK5pj&q=85&s=dbd3eafa7a618802575175dff46aa469" alt="Instruction Adherence Metrics - After Optimization" width="1920" height="205" data-path="images/g2/chatbot-trace-improvement.png" />

As demonstrated in the metrics 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 metrics, you can ensure your AI models consistently follow instructions as intended.
