unified-error-protocol

A shared format for reporting application errors between a backend and its frontend. It defines response bodies and when errors use HTTP status codes such as 200, 401, 403, 404, 413, or 500.

In plain words
What is it for?
Use it when designing JSON endpoints, authentication failures, business errors, streaming responses, and frontend error handling.
Why use it?
It gives clients one predictable way to detect and display errors, including errors from streaming APIs.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/microsoft/data-formulator/unified-error-protocol
Clone the repo
git clone --depth 1 https://github.com/microsoft/data-formulator

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,811 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01811
Opus 5 $0.00000 $0.00905
Sonnet 5 $0.00000 $0.00362
Haiku 4.5 $0.00000 $0.00181

Measured yesterday against content hash c80fbd20128f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

unified-error-protocol scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/unified-error-protocol.mdc · 176 lines

How it starts

The opening of the file, as written. The whole thing — 176 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Unified Error Protocol

See docs/dev-guides/7-unified-error-handling.md for the full developer guide.

HTTP Status Code Policy

All application-controlled errors return HTTP 200 with status: "error" in the body. This applies to both non-streaming JSON APIs and streaming pre-flight errors.

Only these scenarios use non-200:

  • 401AUTH_REQUIRED / AUTH_EXPIRED (so transport layer can intercept)
  • 403ACCESS_DENIED (so transport layer can intercept)
  • 404 — Flask routing: no matching route handler
  • 413 — WSGI: request body exceeds MAX_CONTENT_LENGTH
  • 500 — Unhandled exception that escaped all error handling

Streaming NDJSON APIs:

  • Pre-stream validation failure: HTTP 200 + application/json (use stream_preflight_error())
  • In-stream error: NDJSON {"type": "error", "error": {...}}
  • In-stream warning: NDJSON {"type": "warning", "warning": {...}}

Backend: Non-streaming JSON Format

// Success (HTTP 200)
{"status": "success", "data": {...}}

// Error (HTTP 200 for business errors, 401/403 for auth errors)
{
    "status": "error",
    "error": {
        "code": "TABLE_NOT_FOUND",
        "message": "Table not found",
        "retry": false,
        "detail": "..."  // Only in debug mode
    }
}

Backend: Streaming NDJSON Format

All streaming endpoints use application/x-ndjson. Each line is one JSON object:

{"type": "text_delta", "data": {...}}
{"type": "error", "error": {"code": "LLM_TIMEOUT", "message": "...", "retry": true}}
{"type": "done", "data": {...}}

Backend: How to Handle Errors

from data_formulator.errors import AppError, ErrorCode
from data_formulator.error_handler import json_ok, stream_preflight_error
from data_formulator.error_handler import stream_error_event, classify_and_wrap_llm_error

# Non-streaming: success
return json_ok(data)

# Non-streaming: error (global handler returns HTTP 200, auth errors get 401/403)
raise AppError(ErrorCode.TABLE_NOT_FOUND, "Table not found")

# Streaming: pre-flight error (always HTTP 200)
return stream_preflight_error(AppError(ErrorCode.INVALID_REQUEST, "Bad input"))

# Streaming: in-stream error
yield stream_error_event(classify_and_wrap_llm_error(e))

Read the full file on GitHub · 176 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 176 lines · 0 tokens per session scan A c80fbd20128f

Subscribe to this mod's changes

unified-error-protocol is a cursor rule published in the GitHub repository microsoft/data-formulator (17,048 stars, last pushed 3d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,811 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.