error-response-safety

A project rule for safely handling errors returned by HTTP services. It says not to expose raw exception text, which can contain private details such as file paths, credentials, or internal addresses.

In plain words
What is it for?
Use it when adding or changing API error paths, especially in Python routes, streaming responses, authentication errors, and calls to outside services.
Why use it?
It prevents server errors from leaking sensitive implementation details and keeps error responses in the project's expected format.

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/error-response-safety
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,384 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.01384
Opus 5 $0.00000 $0.00692
Sonnet 5 $0.00000 $0.00277
Haiku 4.5 $0.00000 $0.00138

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

Security

Grade A, and why

error-response-safety 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/error-response-safety.mdc · 160 lines

How it starts

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

Error Response Safety

Never return raw exception text (str(e), f"...{e}") directly in HTTP responses. Python exceptions may contain stack traces, file paths, database connection strings, API keys, or internal IP addresses — all of which are security risks (CWE-209).

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

Unified Error System

New error paths should use the AppError / error_handler infrastructure from errors.py and error_handler.py. Legacy message / error_message bodies are historical formats; do not add compatibility branches for them in new code. All application-controlled errors return HTTP 200 with status: "error" in the body. Only auth errors (401/403) and uncontrolled transport errors (404/413/500) use non-200.

Non-streaming routes

Raise AppError for new code or when structured error codes are useful. The global error handler returns HTTP 200 + JSON error envelope:

from data_formulator.errors import AppError, ErrorCode

# Business error — raise with appropriate code and safe message
raise AppError(ErrorCode.TABLE_NOT_FOUND, "Table not found")

# LLM / external API error — use classify_and_wrap_llm_error
from data_formulator.error_handler import classify_and_wrap_llm_error

except Exception as e:
    raise classify_and_wrap_llm_error(e) from e

Streaming routes

Use stream_error_event() to yield a unified NDJSON error line. Validation before the stream starts returns 200 application/json (not NDJSON):

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

except AppError as e:
    yield stream_error_event(e)
except Exception as e:
    yield stream_error_event(classify_and_wrap_llm_error(e))

Real examples from migrated endpoints

# /data-agent-streaming — standard NDJSON error event
except Exception as e:
    logger.error("Error in data-agent-streaming", exc_info=e)
    from data_formulator.error_handler import stream_error_event, classify_and_wrap_llm_error
    yield stream_error_event(classify_and_wrap_llm_error(e))

# /generate-report-chat — same pattern
except Exception as e:
    logger.exception("generate-report-chat failed")
    from data_formulator.error_handler import stream_error_event, classify_and_wrap_llm_error
    yield stream_error_event(classify_and_wrap_llm_error(e))

# Validation failure before stream starts — use 200 JSON, not NDJSON
if not request.is_json:
    return stream_preflight_error(AppError(ErrorCode.INVALID_REQUEST, "Invalid request"))

Read the full file on GitHub · 160 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 · 160 lines · 0 tokens per session scan A 15b5baa3e0af

Subscribe to this mod's changes

error-response-safety 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,384 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.