# H7: Role Confusion

The message sequence contains a selected role or ordering inconsistency.

<div class="rule-facts"><span>H7</span><span>MEDIUM–CRITICAL</span><span>LintLang 0.8.0</span></div>

**Applies to:** Recognized structured message arrays; not Python extraction mode. Manual repair; no automatic fix for this example.

## What triggers it

Checks multiple system messages, a misplaced system message, consecutive same-role user/assistant messages, orphan tool results, and missing roles. It does not validate every provider protocol.

## How to repair it

Repair the message array according to the target API. In this example, consolidate the two system instructions into the leading system message.

## Reproduce the finding

Use [uv and Python 3.10+](/docs/install), plus curl. Run the examples in a scratch directory.

[Download the finding example](/examples/rules/h7-bad.json).

```json
{
  "messages": [
    {
      "role": "system",
      "content": "Review invoice totals."
    },
    {
      "role": "system",
      "content": "Return discrepancies as JSON."
    },
    {
      "role": "user",
      "content": "Check this invoice."
    }
  ]
}
```

```sh
curl -fsS https://lintlang.ai/examples/rules/h7-bad.json -o h7-bad.json
uvx --from lintlang==0.8.0 lintlang scan h7-bad.json --format json
```

Expected with **0.8.0**: the JSON report includes **H7**, severity **HIGH**. This example exercises multiple system messages. Confirm your provider’s message contract before changing production conversation ordering.

## Improved example

[Download the improved example](/examples/rules/h7-improved.json).

```json
{
  "messages": [
    {
      "role": "system",
      "content": "Review invoice totals and return discrepancies as JSON."
    },
    {
      "role": "user",
      "content": "Check this invoice."
    }
  ]
}
```

```sh
curl -fsS https://lintlang.ai/examples/rules/h7-improved.json -o h7-improved.json
uvx --from lintlang==0.8.0 lintlang scan h7-improved.json --format json
```

Expected with **0.8.0**: **H7 is absent**. Other diagnostics may still appear; this repair targets the rule above.

Both commands use advisory mode: a finding does not itself make the command fail. To fail CI on HIGH or CRITICAL findings, add --fail-on fail. --fail-on review also gates MEDIUM. See [outputs and exit codes](/docs/outputs).

## Detection details

<details>
<summary>Released H7 detection contract and scope</summary>

Checks multiple system messages, a system message not at position zero,
consecutive same-role messages, orphan tool results without preceding tool use,
and messages missing a role. Coverage is limited to recognized message arrays,
not every provider's protocol.

</details>

[All scan rules](/rules) · [Quickstart](/docs/quickstart) · [Separate preflight checks](/docs/preflight).

