Cursor Rules TemplatesCursor Rules Template

Cursor Rules Template: Python FastAPI LangChain Postgres AI Research Assistant

Cursor rules template for building an AI research assistant that summarizes papers, extracts claims, builds mind maps, and generates reports using Python, FastAPI, LangChain, and PostgreSQL.

.cursorrules templatecursor-rulescursor rules templatepython fastapi langchain postgres cursor rulesai research assistant cursor rulespapers summarization cursor rulesclaims extraction cursor rulesmind map generation cursor rulesreports generation cursor rulesCursor AI rulescursor-rules-template-python-fastapi-langchain-postgres

Target User

Developers integrating a research-focused AI assistant stack

Use Cases

  • Summarize academic papers (PDF/text)
  • Extract claims with provenance
  • Construct mind maps for literature
  • Generate structured reports and dashboards

Markdown Template

Cursor Rules Template: Python FastAPI LangChain Postgres AI Research Assistant

# Cursor Rules for Python FastAPI LangChain Postgres AI Research Assistant
[Framework Role & Context]
You are Cursor AI, a research assistant that summarizes papers, extracts claims, builds mind maps, and generates reports. You operate on Python 3.11+, FastAPI, LangChain (or equivalent), and PostgreSQL. You must be precise, cite sources, and produce structured outputs suitable for downstream dashboards.

[Code Style and Style Guides]
Follow PEP 8, type hints, docstrings. Use clear, explicit names. Return types must be annotated. Include error handling and input validation.

[Architecture & Directory Rules]
Root structure should include app/, data/, tests/, migrations/, docs/. Use a modular, testable layout.

[Authentication & Security Rules]
Implement OAuth2 with JWT for API endpoints. Do not log secrets. Use environment configs and 0-trust networking in production.

[Database and ORM patterns]
Use SQLAlchemy ORM with async sessions where supported. Define models in app/models. Use Alembic for migrations. Parameterize all queries and avoid raw SQL in business logic.

[Testing & Linting Workflows]
pytest with pytest-asyncio for async code, mypy type checks, and flake8 linting. Pre-commit hooks should run locally and in CI.

[Prohibited Actions and Anti-patterns for the AI]
Do not bypass authentication, access arbitrary user files without permission, or execute system commands. Do not generate unsafe SQL or code that could harm users. Do not perform web scraping without consent.

Overview

Direct answer: This Cursor Rules Template configures Cursor AI to function as an AI research assistant that summarizes papers, extracts claims, builds mind maps, and generates reports. It targets a Python FastAPI + LangChain + PostgreSQL stack and provides concrete guardrails, prompts, and file structure to enable reproducible research workflows.

The Cursor Rules Template is designed for developers who want a copyable, production-ready configuration that can be dropped into a project root to bootstrap an AI-assisted research pipeline.

When to Use These Cursor Rules

  • In projects that ingest academic papers (PDF/text) and produce concise summaries with citations.
  • When you need structured extraction of claims, hypotheses, and methodological details from sources.
  • To generate mind maps that visualize argument structures and evidence chains.
  • When you want repeatable reporting templates (literature reviews, state-of-the-art surveys).
  • To enforce safe AI usage with explicit guardrails and auditable outputs.

Copyable .cursorrules Configuration

# Cursor Rules for Python FastAPI LangChain Postgres AI Research Assistant
[Framework Role & Context]
You are Cursor AI, a research assistant that summarizes papers, extracts claims, builds mind maps, and generates reports. You operate on Python 3.11+, FastAPI, LangChain (or equivalent), and PostgreSQL. You must be precise, cite sources, and produce structured outputs suitable for downstream dashboards.

[Code Style and Style Guides]
Follow PEP 8, type hints, docstrings. Use clear, explicit names. Return types must be annotated. Include error handling and input validation.

[Architecture & Directory Rules]
Root structure should include app/, data/, tests/, migrations/, docs/. Use a modular, testable layout.

[Authentication & Security Rules]
Implement OAuth2 with JWT for API endpoints. Do not log secrets. Use environment configs and 0-trust networking in production.

[Database and ORM patterns]
Use SQLAlchemy ORM with async sessions where supported. Define models in app/models. Use Alembic for migrations. Parameterize all queries and avoid raw SQL in business logic.

[Testing & Linting Workflows]
pytest with pytest-asyncio for async code, mypy type checks, and flake8 linting. Pre-commit hooks should run locally and in CI.

[Prohibited Actions and Anti-patterns for the AI]
Do not bypass authentication, access arbitrary user files without permission, or execute system commands. Do not generate unsafe SQL or code that could harm users. Do not perform web scraping without consent.

Recommended Project Structure

ai-research-assistant/
├── app/
│   ├── __init__.py
│   ├── main.py
│   ├── api/
│   │   └── v1/
│   │       └── papers.py
│   ├── models/
│   │   └── paper.py
│   ├── services/
│   │   └── paper_processor.py
│   ├── schemas/
│   │   └── paper.py
│   ├── core/
│   │   └── config.py
│   └── db/
│       └── session.py
├── data/
│   ├── papers/
│   └── prompts/
├── tests/
│   ├── test_papers.py
│   └── test_api.py
├── migrations/
└── notebooks/

Core Engineering Principles

  • Single responsibility: each module handles one concern (API, processing, data access).
  • Explicit interfaces: clear function signatures and contracts between components.
  • Observability: structured logging, traces, metrics for the research pipeline.
  • Security by design: secrets management, access control, and validation at every boundary.
  • Data provenance: preserve immutable citations and versioned summaries.

Code Construction Rules

  • Endpoints must be async; use async SQLAlchemy sessions; avoid blocking calls in FastAPI handlers.
  • Use LangChain for orchestration of summarization and claim extraction; ensure deterministic prompts with templates.
  • All database writes should be done via ORM models; avoid ad-hoc SQL in business logic.
  • Return structured results with explicit fields: summary, claims[], mindmap, report_sections, citations.
  • Include input validation with pydantic models and meaningful error messages.
  • Prompts must be templated; avoid hard-coded strings spread across code.
  • Do not rely on client-side rendering for critical data; generate server-side and return JSON.

Security and Production Rules

  • Store secrets in environment variables or secret managers; do not check them into VCS.
  • Use TLS, enable rate limiting, and validate requests against schema.
  • Implement role-based access control for endpoints; restrict heavy CPU tasks to background workers.
  • Audit trails for processing paper data and user actions.

Testing Checklist

  • Unit tests for paper parsing and summarization helpers.
  • Integration tests for API endpoints and database interactions.
  • End-to-end tests simulating real paper input and end outputs.
  • Static type checks with mypy; linting with flake8; run in CI.

Common Mistakes to Avoid

  • Overloading endpoints with heavy compute; prefer background tasks for long-running work.
  • Hardcoding thresholds or prompts; use configurable parameters.
  • Skipping migrations when model changes occur; keep schema in sync with code.
  • Ignoring data provenance and citations in generated outputs.

Related Cursor rules templates

Explore adjacent Cursor rules templates for similar stacks, workflows, and production constraints.

FAQ

What is the purpose of these Cursor rules?

They provide an executable template for building a Python FastAPI + LangChain + PostgreSQL AI research assistant that summarizes papers, extracts claims, creates mind maps, and generates reports.

Which stack is this Cursor Rules Template tailored to?

Python 3.11+, FastAPI, LangChain (or equivalent), PostgreSQL via SQLAlchemy, Alembic, and related tooling for testing and linting.

Can I adapt this to other databases?

Yes, but you should replace the ORM layer and adapt migrations and connection handling to the target database while preserving the prompts and workflow orchestration.

How are claims and citations represented?

Claims are extracted with provenance and mapped to citations in the paper's reference section; mind map nodes link to sections and claims with citations for traceability.

Is security considered?

Yes. The rules enforce OAuth2 with JWT, secret management, and restricted access to data pipelines; all external calls are validated and auditable.