Blog

    Build AI Agent Rule Files with Cursor: Rules on PHI, Tests and Commits for a Healthcare Codebase

    By GauravSeptember 23, 20269 mins read
    On this page

    To build AI agent rule files with Cursor is to write down, once, the standing instructions an AI coding agent must follow on every task in your repository. In a healthcare codebase those rules carry more weight than style preferences: they decide whether patient data ends up in a prompt, a fixture or a log line, and whether the agent's commits can be trusted.

    Engineering leaders and developers at health technology companies will find what belongs in rule files, how to split them, what the rules should say about PHI, tests and commits, and how to keep them working as the codebase grows.

    How do you build AI agent rule files with Cursor for a healthcare codebase?

    You build AI agent rule files with Cursor by writing short, version-controlled rule files in the repository that state how the agent must handle protected health information, test data, tests and commits, scoping each file to the parts of the codebase it governs, and reviewing changes to the rules like code.

    Rolling out AI coding agents in a health tech team?

    We help teams set up agent rules, workflows and review practices that fit regulated code.

    Cursor's documentation says project rules live in the .cursor/rules folder as .mdc files that are version-controlled with the codebase. Each rule has frontmatter fields named description, globs and alwaysApply, rule contents are included at the start of the model context when applied, and the docs advise keeping rules under 500 lines.

    Because rule contents are placed in the model's context on every relevant request, each line has a cost. Rules should be the instructions that must hold every time, not everything the team knows.

    What belongs in a rule file and what does not?

    A rule file holds the standing instructions that apply to every task in its scope; a feature spec holds the requirements for one change. Mixing the two makes rule files long and specs incomplete.

    • Belongs: commands to build, test and lint, and the order to run them.
    • Belongs: hard limits, such as never using real patient data or never editing generated files.
    • Belongs: conventions the agent gets wrong without being told, such as error handling or folder layout.
    • Does not belong: the requirements of the current feature or ticket.
    • Does not belong: long background documents the agent can read on request instead.

    How should the rules be split?

    The rules should be split by scope, so the agent loads the PHI rules everywhere, the test rules when it works on tests, and the migration rules only when it touches the database. The layout below is an example, not a standard.

    Example rule file layout for a healthcare codebase
    Rule fileWhen it appliesWhat it covers
    coreAlwaysStack, commands, folder layout and the short list of things never to do
    phi-handlingAlwaysPatient data in prompts, fixtures, logs, errors and third-party calls
    testingTest files and test foldersSynthetic data, required test types and how to run them
    databaseMigration and schema filesReversible migrations, no data edits in schema changes
    integrationsInterface code, such as FHIR or HL7 v2 adaptersMessage handling, retries and what may be logged
    commitsOn request before committingMessage format, checks to run and what never to commit

    What should the PHI rules say?

    The PHI rules should say that the agent never brings real patient data into the development workflow and never writes code that sends it somewhere new without review. They apply to every file, so keep them short and absolute.

    • Never paste, request or generate real patient records in prompts, fixtures, seed files or examples.
    • Use the project's synthetic data generator for any test or demo data.
    • Never log request bodies, patient names, identifiers or clinical values; log record IDs and outcomes instead.
    • Never add a new external service, SDK or analytics call that could receive patient data; flag it for human review.
    • Keep error messages returned to clients free of patient details.

    Under the HIPAA Safe Harbor method, 45 CFR 164.514(b)(2), health information counts as de-identified only when 18 listed identifiers of the individual and of relatives, employers or household members are removed, including names, small geographic subdivisions, dates other than the year, phone numbers, email addresses and medical record numbers, and the entity has no actual knowledge that the rest could identify the person.

    That list is a useful guide for synthetic data: fixtures should contain none of those identifiers drawn from real people. Generated names, dates and record numbers keep tests realistic without creating a new copy of patient data.

    Rules reduce risk but do not replace controls. Keep production data out of developer environments in the first place, and use the editor's ignore settings for files the agent must never read.

    What should the test rules say?

    The test rules should say which tests the agent must write or update with every change, how to run them, and that a task is not done until they pass.

    • Write or update unit tests for every changed function, using synthetic data only.
    • Add an integration test when an endpoint, message format or database query changes.
    • Run the full test command before reporting a task as complete, and include the result.
    • Never delete or weaken an existing test to make a change pass; explain the conflict instead.

    What should the commit rules say?

    The commit rules should say how the agent prepares commits so that history stays readable and nothing sensitive is committed. In regulated work, the commit log is part of the evidence of how the software changed.

    • One logical change per commit, with a message that says what changed and why.
    • Run lint, type checks and tests before committing, and never bypass hooks.
    • Never commit secrets, environment files, data exports or generated build output.
    • Stage files by explicit path rather than adding everything in the folder.
    • Follow the team's policy on attribution and on which branches the agent may push to.

    What should rules say about integration code?

    Rules for integration code should say how the agent handles messages from EHRs, labs and payers, because that code moves patient data between systems and fails in ways tests rarely cover. Scope these rules to the integration folders so they load only there.

    • Use recorded, de-identified sample messages for FHIR resources and HL7 v2 messages, never live feeds.
    • Log message IDs, types and outcomes, not message bodies.
    • Make handlers safe to retry, and never drop a message silently on a parsing error.
    • Flag any change to field mappings for review by the engineer who owns the interface.

    Integration rules change less often than feature code, but a wrong mapping can reach many patient records before anyone notices. A short, specific rule set here repays the effort.

    How do you write a rule the agent follows?

    You write a rule the agent follows by making it short, specific and testable, in the imperative, with an example where the right behaviour is not obvious.

    • Specific: use parameterized queries for all database access, not write secure code.
    • Imperative: never, always and must, rather than try to or prefer where possible.
    • Example: show one correct log line next to the rule about logging.
    • Reference: point to a file the agent can open instead of copying it into the rule.

    How do you test and maintain the rules?

    You test the rules by giving the agent tasks that tempt it to break them and checking what it does, and you maintain them by changing them through pull requests with a reviewer.

    When a reviewer finds the same agent mistake twice, add or sharpen a rule. When a rule never matters, delete it. A rule set that only grows becomes noise the agent learns to ignore.

    How do teams introduce rule files step by step?

    Teams introduce rule files step by step, starting with the rules that protect patient data and growing from review findings.

    • Step 1: write the core and PHI rules, keeping both short.
    • Step 2: add test and commit rules that match your existing pipeline.
    • Step 3: try the agent on a few real tasks and note where it went wrong.
    • Step 4: add scoped rules for the areas where mistakes appeared.
    • Step 5: require review for every rule change and revisit the set regularly.

    What are the common mistakes with AI agent rule files?

    The common mistakes with AI agent rule files are writing too much, writing too vaguely and treating the rules as a security control.

    • Pasting a whole engineering handbook into an always-applied rule.
    • Vague instructions such as be careful with PHI that the agent cannot act on.
    • Putting feature requirements into rule files, where they outlive the feature.
    • Assuming the rules stop real data reaching the agent, with no environment controls behind them.
    • Editing rules directly on the main branch with no review.

    What do rule files mean for cost and delivery?

    Rule files are a small upfront cost that pays back in review time. The bigger effort is the review discipline and the synthetic data that make the rules workable.

    • Budget for a synthetic data generator if the project does not have one.
    • Give one engineer ownership of the rule set and its reviews.
    • Expect early tasks to surface missing rules, and plan time to add them.

    How Agnotic helps with AI agent rule files

    Agnotic Technologies helps health technology teams set up AI coding agents safely: rule files for PHI, tests and commits, synthetic test data, scoped rules for integrations and review practices for agent-written code. We can run a workshop with your engineers or build features for you under the same rules.

    Agents that follow your rules on every task

    Short, scoped rules for PHI, tests and commits, reviewed like code.

    Sources

    Frequently Asked Questions

    A senior engineer who knows the codebase and the team's data handling rules, with review from whoever owns security or compliance. Engineering leaders at health technology companies should own the decision to use agents at all.

    Talk to an engineer about your project

    Tell us about your codebase and how your team uses AI coding agents. We will suggest the first rules to write and the controls they need behind them.

    Go deeper

    Services and solutions on this topic