# Provide clear error messages

- Check 40.03 · AI agent compatibility · Experimental
- Source: https://checklist-seo-geo.com/en/ai-agent-compatibility/provide-clear-error-messages
- Write and mark up error messages that say what to fix, linked to the field and persistent, so that humans and AI agents can complete forms and orders.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/ai-agent-compatibility/provide-clear-error-messages.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## In short

A clear error message says what is wrong, where, and how to fix it: “The postal code must contain 5 digits”, placed under the field, linked to it in the code and visible until the error is fixed. For an AI agent filling in a form on the user's behalf, it is the only way to understand why the submission failed and to try again correctly. Once this check is done, every error in your key journeys is described in text, attached to the field concerned and announced to assistive technologies, and the form keeps the data already entered. This topic is experimental: agents do not document how they handle errors.

## Why it matters

An agent that submits a form then observes the page: a new screenshot, a new accessibility tree or new text. If the page only shows a red border, a notification that disappears after three seconds or “An error occurred”, it cannot know which field to fix. It tries again with the same input, gives up or asks the user, who knows no more. Anthropic's documentation on the *computer use* tool notes that the model sometimes assumes an action succeeded without checking its result, and recommends having it check the screen after each step: an explicit, persistent error message makes that check possible.

The same flaws block humans, and the WCAG (Web Content Accessibility Guidelines) success criteria describe them: 3.3.1 “Error Identification” (the error is identified in text), 3.3.3 “Error Suggestion” (say how to fix it), 4.1.3 “Status Messages” (announce messages without moving focus), 1.4.1 “Use of Color” (color alone is not enough).

On the technical side, the HTTP status code matters too. A classic form returns the page with a 200 status or redirects; an API call returns an explicit error status (`422` for invalid data, `409` for a conflict, `429` with `Retry-After` for a rate limit) and a readable body.

## What it improves

- **Journeys completed by agents**: the agent fixes the right piece of data instead of looping. A plausible effect, not publicly measured.
- **Human conversion**: fewer abandoned forms and orders. Measure it with [drop-off analysis](https://checklist-seo-geo.com/en/ux-conversion/analyze-drop-offs).
- **Accessibility**: compliance with criteria 3.3.1, 3.3.3 and 4.1.3, and with the equivalent criteria of the French RGAA (Référentiel général d'amélioration de l'accessibilité).
- **Customer support**: fewer “the form doesn't work” requests.
- **Rankings**: no direct effect.

## How to check

Take each key form (contact, quote, sign-up, sign-in, cart, checkout, booking) and submit it three times: empty, with a malformed email address, and with data the server rejects (expired promo code, fully booked slot, out-of-stock item). For each submission, note:

| Check | Compliant |
| --- | --- |
| The message is in text, not only in color or as an icon | yes |
| It names the field and says how to fix it | “Enter an arrival date later than today” |
| It is placed near the field, and a summary appears at the top if there are several errors | yes |
| The field carries `aria-invalid="true"` and the message is linked with `aria-describedby` | yes |
| The message stays displayed until it is fixed | no short-lived notification |
| Valid data already entered is kept | yes, except passwords and card details |
| Focus moves to the summary or to the first field in error | yes |

In Chrome, Elements panel, Accessibility tab, select the field in error: “Invalid user entry” must be `true` and the description must contain the message. The ARIA snapshot script in the guide [use semantic HTML and explicit labels](https://checklist-seo-geo.com/en/ai-agent-compatibility/use-semantic-html-explicit-labels), run after a failed submission, shows what an agent reads.

For an API, check the status and the body:

```bash
curl -s -i -X POST https://example.com/api/reservations -H "Content-Type: application/json" -H "Accept: application/json" -d '{"date":"2020-01-01"}'
```

Compliant result: `HTTP/2 422` and a body that names the field and the rule, not a generic HTML page or a `500`.

## How to implement

### Before you start

Wording: one message per problem, which names the data and the rule, and suggests the fix.

| Avoid | Write |
| --- | --- |
| Invalid field | Enter an email address in the format name@domain.com |
| Error | The postal code must contain 5 digits |
| Incorrect date | The departure date must be after the arrival date (12 March 2027) |
| An error occurred | This slot has just been booked. Available slots: 19:30, 20:00 |
| Invalid promo code | Code HIVER25 expired on 28 February. The displayed price remains €89.00 |
| Payment declined | Your bank declined the payment. No amount has been charged. Try another card |

Markup: disable the browser's native bubbles (`novalidate`), which vary from one browser to another and disappear quickly, but keep the `required`, `type` and `pattern` attributes for the accessibility tree and for JavaScript validation. Always validate on the server side.

Complete template of a field in error, with a summary:

```html
<form action="/reservations" method="post" novalidate>
  <div id="resume-erreurs" role="alert" tabindex="-1">
    <h2>2 errors are preventing the booking from being sent</h2>
    <ul>
      <li><a href="#email">Email: enter an email address in the format name@domain.com</a></li>
      <li><a href="#arrivee">Arrival date: choose a date from 26 November 2026</a></li>
    </ul>
  </div>

  <label for="email">Email</label>
  <input id="email" name="email" type="email" autocomplete="email" required
         value="jean.dupont@exemple" aria-invalid="true" aria-describedby="email-erreur">
  <p id="email-erreur" class="erreur">Error: enter an email address in the format name@domain.com</p>

  <label for="arrivee">Arrival date</label>
  <input id="arrivee" name="arrivee" type="date" min="2026-11-26" required
         value="2026-11-20" aria-invalid="true" aria-describedby="arrivee-erreur">
  <p id="arrivee-erreur" class="erreur">Error: choose a date from 26 November 2026</p>

  <button type="submit">Check availability</button>
</form>
```

After a failed submission rendered by the server, move focus to the summary (`document.getElementById('resume-erreurs').focus()`). For live validation, only announce the error when the user leaves the field, not on every keystroke.

> **Tip:** visually prefix each message with “Error:” or with an icon accompanied by that text. Red alone works neither for color-blind people nor for an agent reading the page text.

Errors outside forms: an out-of-stock item, an unavailable slot or an expired cart are reported in the page with the same rule (what, why, what to do), in a `role="status"` area if the information is not urgent, `role="alert"` if it is blocking. A page that cannot be found returns a real `404` with useful links: see [create a helpful 404 page](https://checklist-seo-geo.com/en/http-redirects/create-helpful-404-page).

### WordPress

Versions: WordPress 6.5 and later, WooCommerce 9 and 10, November 2026.

- **Form plugins**: Contact Form 7, Gravity Forms, WPForms and Fluent Forms display errors under the fields. Customize the texts in each form's message settings: replace “This field is required” with a text that names the data whenever possible, and disable options that only display errors in a tooltip.
- **WooCommerce**: checkout validation errors appear at the top of the checkout block and next to the fields. If you add checks with the `woocommerce_after_checkout_validation` hook (classic checkout), write complete messages:

```php
add_action( 'woocommerce_after_checkout_validation', function ( array $data, WP_Error $errors ): void {
    if ( ! preg_match( '/^\d{5}$/', $data['billing_postcode'] ?? '' ) ) {
        $errors->add( 'validation', __( 'Billing postal code: enter 5 digits, for example 69003.', 'mon-theme' ) );
    }
}, 10, 2 );
```

  The Checkout block relies on the WooCommerce Store API: in that case, use the validation extension points WooCommerce documents for blocks.
- **Temporary notifications**: some themes display add-to-cart messages in a notification that disappears. Set it to stay until it is dismissed.

### Shopify

Versions: Online Store 2.0 themes, Liquid, November 2026.

In Liquid forms (contact, sign-in, sign-up), display errors with their field:

```liquid
{% form 'contact', id: 'ContactForm' %}
  {% if form.errors %}
    <div id="ContactForm-erreurs" role="alert" tabindex="-1">
      <h2>Your message was not sent</h2>
      <ul>
        {% for field in form.errors %}
          <li><a href="#ContactForm-{{ field }}">{{ form.errors.translated_fields[field] | capitalize }}: {{ form.errors.messages[field] }}</a></li>
        {% endfor %}
      </ul>
    </div>
  {% endif %}

  <label for="ContactForm-email">Email</label>
  <input id="ContactForm-email" type="email" name="contact[email]" autocomplete="email" required
    {% if form.errors contains 'email' %}aria-invalid="true" aria-describedby="ContactForm-email-erreur"{% endif %}>
  {% if form.errors contains 'email' %}
    <p id="ContactForm-email-erreur">Error: {{ form.errors.messages['email'] }}</p>
  {% endif %}

  <button type="submit">Send message</button>
{% endform %}
```

Cart errors (quantity higher than the stock) are returned by the Cart Ajax API: display the `description` property of the response in a `role="alert"` area rather than a generic message. Checkout messages are managed by Shopify.

### Laravel

Versions: Laravel 11 to 13.

Laravel keeps the input (`old()`) and the errors after a redirect. Display them linked to the field:

```php
<label for="email">Email</label>
<input id="email" name="email" type="email" value="{{ old('email') }}" autocomplete="email" required
    @error('email') aria-invalid="true" aria-describedby="email-erreur" @enderror>
@error('email')
    <p id="email-erreur" class="erreur">Error: {{ $message }}</p>
@enderror
```

Write messages that say how to fix the problem, in the form request:

```php
public function messages(): array
{
    return [
        'email.email' => 'Enter an email address in the format name@domain.com.',
        'arrivee.after_or_equal' => 'Choose an arrival date from today onwards.',
    ];
}
```

For a French site, the default messages are translated in `lang/fr/validation.php` (publish the language files with `php artisan lang:publish`). For a request that expects JSON, Laravel already returns a `422` with an `errors` object keyed by field.

### Next.js

Versions: Next.js 15 and 16 (App Router).

With a Server Action and `useActionState`, return errors per field and keep the input:

```tsx
'use client';

import { useActionState } from 'react';
import { reserver, type EtatReservation } from './actions';

const etatInitial: EtatReservation = { erreurs: {}, valeurs: {} };

export function FormulaireReservation() {
  const [etat, action, enCours] = useActionState(reserver, etatInitial);
  const erreurEmail = etat.erreurs.email;

  return (
    <form action={action} noValidate>
      <label htmlFor="email">Email</label>
      <input id="email" name="email" type="email" autoComplete="email" required
        defaultValue={etat.valeurs.email}
        aria-invalid={erreurEmail ? true : undefined}
        aria-describedby={erreurEmail ? 'email-erreur' : undefined} />
      {erreurEmail && <p id="email-erreur">Error: {erreurEmail}</p>}

      <button type="submit" disabled={enCours}>Check availability</button>
      <p role="status">{enCours ? 'Checking…' : ''}</p>
    </form>
  );
}
```

In route handlers (`app/api/.../route.ts`), return `Response.json({ errors }, { status: 422 })` rather than a 500 error.

## Common mistakes

- **A red border alone**: no text and no `aria-invalid` state.
- **A short-lived notification** that disappears before it is read or captured.
- **A generic message**: “An error occurred”, “Invalid form”.
- **A form cleared after an error**: the user or the agent has to enter everything again, and often gives up.
- **A button disabled until the form is complete**, without saying what is missing: nothing happens on click and no message appears. Leave the button active and display the errors on submission.
- **A server error returned as a 200** by an API, or a generic `500` error page for a simple piece of invalid data.
- **A message that reveals too much**: “This password is incorrect for jean@exemple.fr” confirms that an account exists. For sign-in, stay neutral: “Incorrect email or password”.

## Frequently asked questions

### Why do error messages matter for AI agents?

An AI agent filling in a form only sees the failure through what the page displays after submission. If the error is just a color, a short-lived notification or a generic message, it does not know which field to fix: it tries again with the same input or gives up. A text message that is linked to the field and persistent lets it fix the right piece of data, just as it lets a human user.

### Should you keep the browser's native validation?

Keep native attributes such as required, type and pattern, but preferably replace the browser's bubbles with your own messages by adding novalidate to the form. Native bubbles vary from browser to browser, disappear quickly and are not part of the page text. Your messages, placed under the field and linked with aria-describedby, remain readable by everyone. Server-side validation remains mandatory in every case.

### Which HTTP status code should a form error return?

For a classic HTML form, the server displays the page again with the errors or redirects to it: the status is then 200 or a redirect. For an API called from JavaScript or by an agent, return an explicit status: 422 for invalid data, 409 for a conflict such as a slot that is already taken, 429 with Retry-After for a rate limit, together with a body that names the field.

### Where should a field's error message go?

Place the message just below the field concerned, or between its label and the field, and link it to the field with aria-describedby. Add the aria-invalid="true" attribute to the field. If the form contains several errors, also display a summary at the top with links to each field and move focus to it. That way, the user, the screen reader and the AI agent find both the list of problems and where they are.

## Resources

- [W3C: Understanding Success Criterion 3.3.1, Error Identification](https://www.w3.org/WAI/WCAG22/Understanding/error-identification.html)
- [W3C: Understanding Success Criterion 3.3.3, Error Suggestion](https://www.w3.org/WAI/WCAG22/Understanding/error-suggestion.html)
- [W3C: Understanding Success Criterion 4.1.3, Status Messages](https://www.w3.org/WAI/WCAG22/Understanding/status-messages.html)
- [W3C WAI: tutorial on form notifications](https://www.w3.org/WAI/tutorials/forms/notifications/)
- [MDN: the aria-invalid attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-invalid)
- [MDN: 422 status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/422)
- [Laravel: validation](https://laravel.com/docs/validation)
- [Anthropic: computer use tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool)

Next steps: [make component states accessible](https://checklist-seo-geo.com/en/ai-agent-compatibility/make-component-states-accessible), [simplify navigation and forms](https://checklist-seo-geo.com/en/ux-conversion/simplify-navigation-forms) and [simplify booking and checkout](https://checklist-seo-geo.com/en/ai-agent-compatibility/simplify-booking-checkout).
