flask

A set of coding rules for Flask, a Python web framework. It covers application setup, feature-specific route groups, configuration, JSON errors, database access, and logging.

In plain words
What is it for?
Use it when creating Flask application factories, blueprints, routes, environment configurations, database code, error handlers, or structured logs.
Why use it?
It establishes a consistent structure for Flask applications and safer handling of secrets and failures. This helps keep production responses useful without exposing internal error details.

Cursor rule

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/nedcodes-ok/cursor-doctor/flask
Clone the repo
git clone --depth 1 https://github.com/nedcodes-ok/cursor-doctor
Per session 465 This file is loaded in full into every session.
When invoked 465 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin 100% copy Near-identical to another mod 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.00465 $0.00465
Opus 5 $0.00233 $0.00233
Sonnet 5 $0.00093 $0.00093
Haiku 4.5 $0.00047 $0.00047

Measured 2d ago against content hash 3ea930bb0550, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

flask 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 2d ago.

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.

Origin

This is a copy

100% identical to flask — 0 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

pro-kit/templates/frameworks/flask.mdc · 45 lines

How it starts

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

Flask Cursor Rules

You are an expert Flask developer. Follow these rules:

Application Structure

  • Application factory pattern (create_app) for all projects. No module-level app instances
  • One Blueprint per feature domain. Register in create_app, not at import time
  • Config classes per environment: DevelopmentConfig, ProductionConfig, TestingConfig
  • Store secrets in environment variables, load via os.environ.get() with no defaults for required values

Blueprints & Routes

  • Prefix all blueprint URLs: bp = Blueprint('auth', name, url_prefix='/auth')
  • Use @bp.before_request for blueprint-scoped middleware (auth checks, rate limiting)
  • Return consistent JSON responses: {"data": ..., "error": null} or {"data": null, "error": {...}}
  • Use flask.abort() with custom error messages, never raise raw HTTP exceptions

Error Handling

  • Register @app.errorhandler for 400, 401, 403, 404, 422, 500 globally
  • Return JSON error responses with status code, message, and request_id
  • Log exceptions with app.logger, not print(). Configure structured logging
  • Never expose stack traces in production responses

Database (SQLAlchemy)

  • Use Flask-SQLAlchemy with scoped sessions. Call db.session.remove() in teardown
  • Models in app/models/, one file per domain entity
  • Always db.session.commit() in try/except with db.session.rollback() in except
  • Use Flask-Migrate for all schema changes, never db.create_all() in production

Request Handling

  • Validate request data with marshmallow or pydantic, not manual dict checks
  • Use @login_required decorator, never check session manually in route body
  • File uploads: validate content type and size before saving. Use secure_filename()
  • Set CSRF protection on all forms. Use Flask-WTF or manual token validation

Testing

  • Use app.test_client() with application context. Fixture: yield create_app('testing')
  • Separate test database. Use transactions for test isolation, rollback after each test
  • Test error handlers explicitly — don't assume Flask defaults are correct

Read the full file on GitHub · 45 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. 2d ago First seen · 45 lines · 465 tokens per session scan A 3ea930bb0550

Subscribe to this mod's changes

flask is a cursor rule published in the GitHub repository nedcodes-ok/cursor-doctor (9 stars, last pushed 5mo ago), licensed MIT. It adds 465 tokens to every session, about $0.0023 per session on Opus 5. A static security scan graded it A with 0 findings. It is 100% identical to flask, differing in 0 lines, and is treated as a copy.