Cursor Rules Template: Ollama Local LLM + LangGraph Integration
Cursor Rules Template for Ollama Local LLM with LangGraph integration, featuring a copyable .cursorrules block and stack-specific guidance for Cursor AI.
Target User
Developers building local LLM apps with Ollama and LangGraph via Cursor AI
Use Cases
- Local LLM prototyping with Ollama
- LangGraph graph-based prompts
- Cursor AI workflow orchestration with local models
Markdown Template
Cursor Rules Template: Ollama Local LLM + LangGraph Integration
# Cursor Rules Template for Ollama + LangGraph Integration
Version
- cursorrules: 0.1
Framework Role & Context
- You are Cursor AI configured to assist with local LLM applications that use Ollama for model serving and LangGraph for graph-based agent orchestration.
- Keep the application local-first by default. Prefer explicit graph nodes, deterministic state transitions, and testable prompt/runtime boundaries.
- When requirements are unclear, ask before changing graph topology, model runtime behavior, persistence, or security boundaries.
Code Style and Style Guides
- Follow the repository's Python and TypeScript lint rules.
- Keep model adapters, graph definitions, prompts, tools, and tests in separate modules.
- Use clear names for graph state, nodes, edges, tool calls, model configuration, and prompt files.
- Avoid hidden global state and avoid mixing prompt construction directly into graph execution code.
Architecture & Directory Rules
- Place Ollama runtime wrappers under llm/ollama/.
- Place LangGraph graph definitions under langgraph/graphs/.
- Store prompts in prompts/ and keep prompt versions reviewable.
- Store Cursor rules and related AI coding guardrails under rules/cursor/.
- Keep tests close to the graph, model adapter, prompt, and tool behavior they validate.
Authentication & Security Rules
- Default to local execution without external API keys.
- Use environment variables for any sensitive runtime configuration.
- Do not write secrets, chat transcripts, local files, or model outputs outside approved project directories.
- Restrict filesystem access to the project root unless the user explicitly approves a different scope.
Database and Persistence Rules
- No database is required for simple prompt and graph workflows.
- If persistence is needed, use local SQLite with restricted permissions or an explicitly configured project-local store.
- Keep persisted graph state minimal, auditable, and free of secrets unless encryption and retention rules are defined.
Testing & Linting Workflows
- Use pytest for Python unit and integration tests.
- Use Ruff or flake8 for linting and keep pre-commit checks deterministic.
- Test graph transitions, prompt rendering, model adapter fallbacks, tool guards, and local runtime error handling.
- Mock Ollama responses where deterministic tests are required.
Prohibited Actions and Anti-patterns for the AI
- Do not call remote model APIs unless the user explicitly changes the local-only requirement.
- Do not fetch external code or install packages without approval.
- Do not spawn shell commands without clear sanitization and user intent.
- Do not write secrets to disk, logs, prompts, graph state, or test fixtures.
- Do not add libraries that conflict with Ollama, LangGraph, or the project's local-first runtime model.Overview
This Cursor rules template documents a local Ollama LLM integration with LangGraph for Cursor AI. It targets a locally hosted language model workflow with graph-based prompts, routing, and safety guardrails. The configuration provides a copyable .cursorrules block and stack-specific guidance to help developers implement and validate a secure local LLM pipeline.
When to Use These Cursor Rules
- Prototype local LLM apps with Ollama and LangGraph without cloud dependencies
- Define graph-driven prompt orchestration and routing within Cursor AI
- Enforce sandboxed, offline-first execution with reproducible results
- Document architecture and testing practices for local model deployments
Copyable .cursorrules Configuration
Copy the block below into a new file at the project root named .cursorrules.
# Cursor Rules Template for Ollama + LangGraph Integration
Version
- cursorrules: 0.1
Framework Role & Context
- You are Cursor AI configured to assist with local LLM applications that use Ollama for model serving and LangGraph for graph-based agent orchestration.
- Keep the application local-first by default. Prefer explicit graph nodes, deterministic state transitions, and testable prompt/runtime boundaries.
- When requirements are unclear, ask before changing graph topology, model runtime behavior, persistence, or security boundaries.
Code Style and Style Guides
- Follow the repository's Python and TypeScript lint rules.
- Keep model adapters, graph definitions, prompts, tools, and tests in separate modules.
- Use clear names for graph state, nodes, edges, tool calls, model configuration, and prompt files.
- Avoid hidden global state and avoid mixing prompt construction directly into graph execution code.
Architecture & Directory Rules
- Place Ollama runtime wrappers under llm/ollama/.
- Place LangGraph graph definitions under langgraph/graphs/.
- Store prompts in prompts/ and keep prompt versions reviewable.
- Store Cursor rules and related AI coding guardrails under rules/cursor/.
- Keep tests close to the graph, model adapter, prompt, and tool behavior they validate.
Authentication & Security Rules
- Default to local execution without external API keys.
- Use environment variables for any sensitive runtime configuration.
- Do not write secrets, chat transcripts, local files, or model outputs outside approved project directories.
- Restrict filesystem access to the project root unless the user explicitly approves a different scope.
Database and Persistence Rules
- No database is required for simple prompt and graph workflows.
- If persistence is needed, use local SQLite with restricted permissions or an explicitly configured project-local store.
- Keep persisted graph state minimal, auditable, and free of secrets unless encryption and retention rules are defined.
Testing & Linting Workflows
- Use pytest for Python unit and integration tests.
- Use Ruff or flake8 for linting and keep pre-commit checks deterministic.
- Test graph transitions, prompt rendering, model adapter fallbacks, tool guards, and local runtime error handling.
- Mock Ollama responses where deterministic tests are required.
Prohibited Actions and Anti-patterns for the AI
- Do not call remote model APIs unless the user explicitly changes the local-only requirement.
- Do not fetch external code or install packages without approval.
- Do not spawn shell commands without clear sanitization and user intent.
- Do not write secrets to disk, logs, prompts, graph state, or test fixtures.
- Do not add libraries that conflict with Ollama, LangGraph, or the project's local-first runtime model.
Recommended Project Structure
Stack-specific directory tree for the Ollama LangGraph Cursor Rules workflow.
my-ollama-langgraph-app/
├── config/
│ └── settings.py
├── prompts/
│ ├── system.md
│ └── task.md
├── llm/
│ └── ollama/
│ ├── client.py
│ ├── models.py
│ └── runtimes.py
├── langgraph/
│ └── graphs/
│ ├── state.py
│ ├── nodes.py
│ └── workflow.py
├── rules/
│ └── cursor/
│ └── .cursorrules
└── tests/
├── test_ollama_client.py
└── test_langgraph_workflow.pyCore Engineering Principles
- Local-first development with explicit boundaries between local models and tooling
- Deterministic prompts and graph-driven routing for reproducible results
- Explicit separation of concerns between LLM invocation, graph logic, and orchestration
- Transparent, versioned prompts and guardrails to reduce drift
- Environment-isolated deployments with pinned model versions
Code Construction Rules
- Use only Ollama for local LLM and LangGraph for graph operations
- Keep prompts in prompts/ with a clear file naming convention
- Place all Cursor rules in a root level .cursorrules file
- Do not embed API keys or tokens in code or prompts
- Validate prompts against a schema and unit-test prompt templates
- Ensure output length and token usage are bounded for offline runtimes
- Respect directory boundaries and avoid writing to protected paths
Security and Production Rules
- Run Ollama in a restricted user context with limited file permissions
- Disable external network access for the runtime; use local resources only
- Pin model versions and LangGraph dependencies to specific, tested revisions
- Store secrets in environment variables, not in code or prompts
- Audit prompts and graphs for safety and bias concerns; implement watchdog constraints
Testing Checklist
- Unit tests for prompt rendering and graph routing
- Integration tests that exercise Ollama invocation and LangGraph graph processing
- End-to-end tests that cover a full Cursor AI workflow with a local model
- Linting and style checks integrated into CI; ensure deterministic outputs
- Validate that no external network calls are made during tests
Common Mistakes to Avoid
- Assuming cloud APIs are available in local mode
- Overlooking prompt guardrails leading to unsafe or leaking data
- Mixing up model versions or graph configurations across environments
- Neglecting to commit the .cursorrules and prompt templates
- Ignoring test coverage for local only workflows
FAQ
What is the purpose of this Cursor Rules Template for Ollama and LangGraph?
This template provides concrete Cursor AI instructions to configure a local Ollama LLM with LangGraph graphs, including a copyable .cursorrules block, stack-specific file layout, and guardrails to keep AI-assisted development safe.
What stack does this template target?
It targets a local Ollama LLM integrated with LangGraph for graph-based prompting and routing, leveraging Cursor AI rules to ensure secure, reproducible deployments.
How do I apply the .cursorrules block?
Copy the code block from the Copyable .cursorrules Configuration section and paste it into a new file at the project root named .cursorrules. Cursor AI will read this block during local execution.
Where should I place the template in my project?
Place the .cursorrules file and supporting scaffolding under your project root as defined by the Recommended Project Structure, ensuring it is committed to version control.
Related implementation resources: AI Use Case for Demolition Contractors Using Sensor Logs To Optimize Explosive Placement for Safe Building Implosions and Threat Auditing AI Systems: Simulating Malicious User Inputs to Validate Defenses.