How to ensure rules are applied?

I have the following scenario

.cursor/rules/python/python-coding-style.mdc

In there I have:

---
description: Strict Python conventions for /python3
globs: python3/**
alwaysApply: false
---
...
## 2. Functions (Strict)

- **Hard Limit:** Maximum **15 lines** of code per function (excluding function signature).
…

Then I went inside /python3 and to a specific file inside and asked the LLM to combine 5 functions into one.
Expectation: Tell me that this would go against the rule or at least in the thought process I would have expected to see it thinking about this.
What happened: It did as asked with no mentioning that it goes against the rule.

Is this behavior correct?

How do I know it actually looked at the rule? Among other things, you are adding the “yaml” part of all rules to the system prompt and that’s why I do not see it in the chat history? Assuming the “yaml” part is in the sys prompt, in my example I would have expected it to then explore the rule file as the edited file is inside the defined globs… but I did not see any such evidence in the chat history.

There unfortunately is no “correct” behavior here.

It will change depending on which model you use; some will mention “hey, your rule says this, are you sure?” … but others will simply do what you tell them even if it conflicts.

Unfortunately you can’t (that I know of). At one point the chat UI would show if it used a rule, but Cursor changes their UI so damn often that I’m pretty sure that feature got left behind.

In my experience, rules with alwaysApply: false never get consistently applied when I would expect them to. Eventually I gave up and would just manually include rules when I knew I needed them. Kinda annoying, but better quality results.

Even once the rule is included, though, there’s no guarantee the AI will follow the rules. Especially if it conflicts with either your prompt or perhaps the system prompt… or just good old-fashioned AI hallucination mistakes :person_shrugging:

TL;DR hope for the best but always double-check the AI work to make sure it followed your rules correctly

Hey, point by point.

Your rule with alwaysApply: false plus globs: python3/** is for Apply to Specific Files mode, docs Rules | Cursor Docs. The idea is that the agent should pick it up when there is a file in context that matches the glob. In practice, glob-scoped rules are being picked up unreliably right now, and we’ve seen quite a few similar reports over the last couple of months:

We’re tracking the issue, but I can’t share an ETA for a fix yet.

About how to check if a rule was actually used, there isn’t a reliable indicator in the UI right now. There’s an open feature request for that, Show which rules are injected into prompts, feel free to subscribe and upvote.

Workarounds that tend to be more reliable:

  • Set alwaysApply: true for critical rules like style, function limits, etc, so the rule content is guaranteed to go into the system prompt.
  • Or manually @ mention the rule in chat when you’re working on that topic.

One more note: even when a rule is injected, different models handle rules differently. Some will mention a conflict like this goes against your rule, should I do it anyway. Others will just follow the request. So it’s still best to do a quick final check of the output yourself.