Skip to content

feat: Add clinical-note-red-flag-scanner template#296

Open
Vilsee wants to merge 3 commits into
Lamatic:mainfrom
Vilsee:feat/clinical-note-red-flag-scanner
Open

feat: Add clinical-note-red-flag-scanner template#296
Vilsee wants to merge 3 commits into
Lamatic:mainfrom
Vilsee:feat/clinical-note-red-flag-scanner

Conversation

@Vilsee

@Vilsee Vilsee commented Jul 26, 2026

Copy link
Copy Markdown

Summary

Adds a Clinical Note Red-Flag Scanner template — a single-flow API pipeline that accepts a clinical note as text and returns a structured, severity-ranked JSON list of documentation red flags for clinician and compliance reviewer triage.

Problem Statement

Clinical documentation frequently ships with silent gaps — missing informed consent language, undocumented drug-interaction risk, incomplete vitals/history, or ambiguous dosing instructions — that create real patient-safety and regulatory exposure (aligned with EU AI Act Article 12 documentation/audit requirements, HIPAA documentation-integrity expectations, and CMS/Joint Commission accreditation standards).

The existing AgentKit registry has a medical-assistant symptom-checker chatbot, but nothing that performs structured compliance analysis of clinical documentation. This template fills that gap — it's not a conversational agent, it's a single-pass analysis tool that outputs machine-readable results for dashboards, alerting systems, and CDI (Clinical Documentation Improvement) workflows.

What This Template Does

  • Scans clinical notes against 10 red-flag categories: CONSENT, DRUG_INTERACTION, ALLERGY, VITALS, HISTORY, DOSING, FOLLOW_UP, ASSESSMENT, IDENTITY, REGULATORY
  • Returns severity-ranked flags (CRITICAL / HIGH / MEDIUM / LOW) with per-flag reasoning, location references, and remediation recommendations
  • Outputs structured JSON — not prose — designed for programmatic consumption
  • Uses Gemini (gemini-3.1-flash-lite-preview) for analysis

Flow Architecture

API Request (clinicalNote: string)
  → Analyse Note (LLMNode — Gemini)
  → Variables (maps generatedResponse → finalText)
  → API Response ({ result: structured JSON })

4 nodes, single flow, template type — no UI, no env vars, no external dependencies beyond a Gemini API key.

Tested Example

Input — a 67M chest pain presentation with intentional documentation gaps:

{
  "clinicalNote": "Patient: John D., 67M. Chief Complaint: Chest pain x 2 hours. History: HTN, DM2. Current Meds: Metformin 500mg BID, Lisinopril 10mg daily. Exam: BP 158/94, HR 88, RR 18. Lungs clear. Heart: regular rhythm, no murmurs. Assessment: Probable angina. Plan: Start aspirin 81mg daily, order stress test. Prescribed nitroglycerin PRN."
}

Output — 5 flags across 5 categories, severity-ranked:

# Category Severity Title
1 IDENTITY CRITICAL Missing Patient Identifiers and Provider Attestation
2 ALLERGY CRITICAL Missing Allergy Information
3 DOSING HIGH Incomplete Medication Dosing Instructions
4 FOLLOW_UP HIGH Incomplete Follow-up and Emergency Plan
5 HISTORY MEDIUM Incomplete Social and Family History

Each flag includes detail, location, and recommendation fields. Full JSON output is in the README.

Files Added

kits/clinical-note-red-flag-scanner/
├── .gitignore
├── README.md
├── agent.md
├── lamatic.config.ts
├── constitutions/
│   └── default.md
├── flows/
│   └── clinical-note-red-flag-scanner.ts
├── model-configs/
│   └── clinical-note-red-flag-scanner_llmnode-453_generative-model-name.ts
└── prompts/
    ├── clinical-note-red-flag-scanner_llmnode-453_system_0.md
    └── clinical-note-red-flag-scanner_llmnode-453_user_1.md

How It Was Built

  • Flow built and deployed in Lamatic Studio (project Clinicalnotescanner717)
  • Tested with real clinical note input — verified structured JSON output
  • Exported from Studio (not hand-crafted) — flow .ts contains authentic runtime IDs and edge metadata
  • Integrated into kits/ following the article-summariser template structure exactly
  • Enhanced lamatic.config.ts, README.md, agent.md, and flow meta with comprehensive documentation

Checklist

  • Template structure mirrors kits/article-summariser/ exactly
  • lamatic.config.ts — type template, author, tags, deploy/github links
  • Flow .ts exported from Lamatic Studio (authentic runtime metadata)
  • Comprehensive agent.md — overview, purpose, flow details (4 nodes), I/O schemas, guardrails
  • README.md — deploy button, category table, real tested example with full JSON output
  • constitutions/default.md — safety guardrails and PII handling
  • No overlap with existing registry.json entries (verified all 79)
  • PR title follows feat: Add ... convention
  • Slug clinical-note-red-flag-scanner is unique in the registry
  • Added kits/clinical-note-red-flag-scanner/ template kit:

    • lamatic.config.ts: Lamatic template configuration (single step wired to CLINICAL_NOTE_RED_FLAG_SCANNER_FLOW_ID), deployment metadata, links, tags.
    • .gitignore: ignores .lamatic/, node_modules/, .env, .env.local.
    • README.md: end-to-end usage docs, category list, severity/output schema, and example input/output JSON.
    • agent.md: AgentKit agent documentation describing the API-invoked single-pass red-flag scanning pipeline.
    • constitutions/default.md: baseline safety/privacy/adversarial-input guardrails (no PII retention/logging, refusal to prompt injection, avoid fabricating, professional tone).
    • flows/clinical-note-red-flag-scanner.ts: single-flow API pipeline definition exporting { meta, inputs, references, nodes, edges }.
    • model-configs/clinical-note-red-flag-scanner_llmnode-453_generative-model-name.ts: Gemini model binding (gemini/gemini-3.1-flash-lite-preview) for LLMNode_453.
    • prompts/clinical-note-red-flag-scanner_llmnode-453_system_0.md: strict system prompt enforcing raw JSON-only output, fixed schema, severity-ranked/unique FLAG-00x ids, and documentation-only remediation.
    • prompts/clinical-note-red-flag-scanner_llmnode-453_user_1.md: user prompt that injects runtime {{triggerNode_1.output.clinicalNote}} into a <clinical_note> block.
  • Flow behavior (clinical-note-red-flag-scanner.ts)—node types and how it works:

    • triggerNode (“API Request”): GraphQL-triggered input accepting clinicalNote with minLength/pattern validation.
    • dynamicNode (“Analyse Note”, LLMNode_453): calls the LLM using the referenced system/user prompt templates and the Gemini model config; produces generatedResponse.
    • dynamicNode (“Variables”, variablesNode_197): maps LLMNode_453.output.generatedResponse into finalText.
    • responseNode (“API Response”, graphqlResponseNode): returns JSON with result set to {{variablesNode_197.output.finalText}}.
    • Edges: defaultEdge between trigger → LLM → variables → response, plus a responseEdge to emit the trigger’s response.

Adds a clinical documentation compliance analysis template that accepts a clinical note as text and returns a structured, severity-ranked JSON list of documentation red flags (missing consent, drug interactions, incomplete vitals, ambiguous dosing, etc.) for clinician and compliance reviewer triage.

- Single-flow template (API Request -> LLM Analyse Note -> Variables -> API Response)

- 10 red-flag categories with 4 severity levels (CRITICAL/HIGH/MEDIUM/LOW)

- Uses Gemini (gemini-3.1-flash-lite-preview) for analysis

- Structured JSON output with per-flag reasoning, location, and remediation

- Includes comprehensive agent.md, README with tested example I/O, and safety constitution
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Vilsee, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 37 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 890157aa-2092-47b7-9d04-38b38c85c39b

📥 Commits

Reviewing files that changed from the base of the PR and between dee8afb and 725cbbe.

📒 Files selected for processing (5)
  • kits/clinical-note-red-flag-scanner/README.md
  • kits/clinical-note-red-flag-scanner/agent.md
  • kits/clinical-note-red-flag-scanner/flows/clinical-note-red-flag-scanner.ts
  • kits/clinical-note-red-flag-scanner/prompts/clinical-note-red-flag-scanner_llmnode-453_system_0.md
  • kits/clinical-note-red-flag-scanner/prompts/clinical-note-red-flag-scanner_llmnode-453_user_1.md

Walkthrough

Changes

Adds a complete Clinical Note Red-Flag Scanner template with Gemini analysis, structured JSON output rules, a four-node execution flow, safety guardrails, documentation, model configuration, and Lamatic packaging metadata.

Clinical Note Red-Flag Scanner

Layer / File(s) Summary
Analysis contract and guardrails
kits/clinical-note-red-flag-scanner/prompts/*, kits/clinical-note-red-flag-scanner/constitutions/default.md, kits/clinical-note-red-flag-scanner/agent.md, kits/clinical-note-red-flag-scanner/README.md
Defines ten red-flag categories, severity-ranked raw JSON output, clinical note interpolation, safety rules, agent behavior, and usage documentation.
Flow execution and model wiring
kits/clinical-note-red-flag-scanner/flows/..., kits/clinical-note-red-flag-scanner/model-configs/...
Connects the API request, Gemini LLM analysis, variable mapping, and JSON response through referenced prompts and model configuration.
Template packaging
kits/clinical-note-red-flag-scanner/lamatic.config.ts, kits/clinical-note-red-flag-scanner/.gitignore
Adds template metadata, deployment links, the mandatory flow step, and local-file exclusions.

Suggested reviewers: amanintech, d-pamneja

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is clear, concise, and matches the main change: adding the clinical-note-red-flag-scanner template.
Description check ✅ Passed The description covers the template purpose, flow, example output, files added, and implementation notes, with only minor template-section gaps.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

:robot_face: AgentKit Structural Validation

New Contributions Detected

  • Template: kits/clinical-note-red-flag-scanner

Check Results

Check Status
No edits to existing kits ✅ Pass
Required root files present ✅ Pass
Flow .ts files present ✅ Pass
lamatic.config.ts valid ✅ Pass
No changes outside kits/ ✅ Pass

🎉 All checks passed! This contribution follows the AgentKit structure.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 13

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@kits/clinical-note-red-flag-scanner/agent.md`:
- Around line 15-19: Revise the standards-alignment section and guardrail claims
in kits/clinical-note-red-flag-scanner/agent.md at lines 15-19 to state only
that the template may support documentation-review workflows, and explicitly
disclaim regulatory compliance certification. Apply the same narrowed wording
and disclaimer to the user-facing compliance statement in
kits/clinical-note-red-flag-scanner/README.md at lines 12-14.
- Around line 29-33: Update the input-note guidance in the agent documentation
to remove the “any length” claim. Define and enforce a maximum supported note
size or implement chunking before scanning, document the actual limit and
behavior for oversized notes, and keep the required clinicalNote input contract
unchanged.

In `@kits/clinical-note-red-flag-scanner/flows/clinical-note-red-flag-scanner.ts`:
- Around line 159-163: Update the finalText mapping in the Variables node to
reference only LLMNode_453.output.generatedResponse, removing the trailing
literal “{” so the complete model response remains valid JSON.
- Around line 110-115: Update the API Request trigger configuration for nodeName
"API Request" so advance_schema requires clinicalNote to be a non-empty,
non-whitespace string. If the schema cannot express trimming, add an explicit
guard immediately before the LLM node that rejects empty or whitespace-only
clinicalNote values before scanning.

In `@kits/clinical-note-red-flag-scanner/lamatic.config.ts`:
- Around line 9-12: Add the deployment environment key to the mandatory step
configuration identified by id "clinical-note-red-flag-scanner", using the step
ID expected by runtime flow resolution so it can read the deployed flow ID from
process.env. Preserve the existing id and type values.

In
`@kits/clinical-note-red-flag-scanner/prompts/clinical-note-red-flag-scanner_llmnode-453_system_0.md`:
- Line 13: Update the REGULATORY guidance in the clinical-note red-flag scanner
prompt to require jurisdiction and care-setting context before emitting
regulatory findings. If those inputs are unavailable, restrict findings to
requirements explicitly identified by the caller or documented in the note; do
not make jurisdiction-specific claims from clinicalNote alone.
- Line 5: Update the DRUG_INTERACTION category definition in the system prompt
to avoid claiming definitive or exhaustive detection without an authoritative
interaction source; either specify a versioned, clinically verified interaction
database/tool, or restrict findings to interactions explicitly documented in the
note and label screening as non-exhaustive.
- Around line 23-27: Update the recommendation field instructions and the
prohibition near the medical-advice guidance to require documentation-only
remediation actions. Explicitly prohibit treatment choices, dosing regimens,
diagnoses, and triage or emergency-care advice, and revise the README example to
remove nitroglycerin and emergency-care instructions.
- Around line 15-30: Update the JSON response contract in the system prompt to
explicitly require that flagCount equals flags.length, flag IDs are unique and
sequential starting at FLAG-001, and category and severity values use only the
defined valid codes. Require responses to satisfy these invariants in addition
to the existing structure.
- Around line 37-42: Update the evidence guidance near the flag-generation rules
so `detail` and `location` use redacted or paraphrased evidence rather than
reproducing exact patient text. Explicitly prohibit names, MRNs, DOBs, contact
information, and other identifiers while preserving enough non-identifying
context to support each flag.

In
`@kits/clinical-note-red-flag-scanner/prompts/clinical-note-red-flag-scanner_llmnode-453_user_1.md`:
- Around line 1-2: Update the clinicalNote interpolation in the clinical-note
scanner prompt to prevent raw PHI from being sent to Gemini. Require a
pre-redacted or de-identified note, or enforce a documented compliant
zero-retention provider configuration before forwarding the content; do not rely
on prompt-level confidentiality instructions.
- Around line 1-2: Update the clinical-note prompt content around
triggerNode_1.output.clinicalNote to clearly delimit the note as untrusted data
and explicitly instruct the model to ignore any commands or instructions
contained within it, while preserving the required JSON, confidentiality, and
safety behavior.

In `@kits/clinical-note-red-flag-scanner/README.md`:
- Around line 1-8: Move the “# Clinical Note Red-Flag Scanner” H1 above the
deploy badge HTML so it is the README’s first content and satisfies MD041. Keep
the existing badge markup unchanged below the heading.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 83786c0b-8632-4fb4-8f70-44be325cb8c6

📥 Commits

Reviewing files that changed from the base of the PR and between bd7fade and a56bd68.

📒 Files selected for processing (9)
  • kits/clinical-note-red-flag-scanner/.gitignore
  • kits/clinical-note-red-flag-scanner/README.md
  • kits/clinical-note-red-flag-scanner/agent.md
  • kits/clinical-note-red-flag-scanner/constitutions/default.md
  • kits/clinical-note-red-flag-scanner/flows/clinical-note-red-flag-scanner.ts
  • kits/clinical-note-red-flag-scanner/lamatic.config.ts
  • kits/clinical-note-red-flag-scanner/model-configs/clinical-note-red-flag-scanner_llmnode-453_generative-model-name.ts
  • kits/clinical-note-red-flag-scanner/prompts/clinical-note-red-flag-scanner_llmnode-453_system_0.md
  • kits/clinical-note-red-flag-scanner/prompts/clinical-note-red-flag-scanner_llmnode-453_user_1.md

Comment thread kits/clinical-note-red-flag-scanner/agent.md Outdated
Comment thread kits/clinical-note-red-flag-scanner/agent.md Outdated
Comment thread kits/clinical-note-red-flag-scanner/lamatic.config.ts
Comment on lines +23 to +27
"severity": "CRITICAL | HIGH | MEDIUM | LOW",
"title": "Brief flag title",
"detail": "Specific explanation of what is missing or problematic",
"location": "Where in the note this issue was found (or 'ABSENT' if the issue is something missing entirely)",
"recommendation": "Specific action to remediate this flag"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Mission-critical: keep remediation guidance documentation-only.

The recommendation field asks for specific actions while Line 41 prohibits medical advice; the README example already supplies a nitroglycerin regimen and emergency-care instructions. Require documentation actions only, and explicitly prohibit treatment choices, dosing regimens, diagnoses, and triage advice.

Also applies to: 41-42

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@kits/clinical-note-red-flag-scanner/prompts/clinical-note-red-flag-scanner_llmnode-453_system_0.md`
around lines 23 - 27, Update the recommendation field instructions and the
prohibition near the medical-advice guidance to require documentation-only
remediation actions. Explicitly prohibit treatment choices, dosing regimens,
diagnoses, and triage or emergency-care advice, and revise the README example to
remove nitroglycerin and emergency-care instructions.

Comment on lines +37 to +42
- Be specific. Cite the exact text or absence that triggered each flag.
- Do not fabricate flags. If the note is well-documented, return fewer flags.
- Sort flags by severity (CRITICAL first, LOW last).
- If no flags are found, return an empty flags array with a positive summary.
- Do not provide medical advice. You are reviewing documentation completeness, not making clinical judgments.
- Treat all patient data as confidential. Do not repeat PII unnecessarily in your output. No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Redact PII from evidence fields.

“Cite the exact text” conflicts with the PII-minimization rule. Require redacted/paraphrased evidence and prohibit repeating names, MRNs, DOBs, contact details, or other identifiers in detail and location.

🧰 Tools
🪛 markdownlint-cli2 (0.23.0)

[warning] 42-42: Files should end with a single newline character

(MD047, single-trailing-newline)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@kits/clinical-note-red-flag-scanner/prompts/clinical-note-red-flag-scanner_llmnode-453_system_0.md`
around lines 37 - 42, Update the evidence guidance near the flag-generation
rules so `detail` and `location` use redacted or paraphrased evidence rather
than reproducing exact patient text. Explicitly prohibit names, MRNs, DOBs,
contact information, and other identifiers while preserving enough
non-identifying context to support each flag.

Comment thread kits/clinical-note-red-flag-scanner/README.md Outdated
- Fix trailing brace in variablesNode mapping

- Add envKey to lamatic.config.ts

- Add minLength validation to flow advance_schema

- Narrow compliance claims and add data privacy warnings in README and agent.md

- Add token limit to agent.md

- Restrict system prompt DRUG_INTERACTION and REGULATORY claims

- Enforce documentation-only recommendations and PII redaction

- Add prompt injection defense to user prompt

- Enforce strict JSON invariants

- Fix markdownlint warnings

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
kits/clinical-note-red-flag-scanner/README.md (3)

67-69: 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Keep the public example fully synthetic and non-identifying.

The sample uses patient-like clinical data and demonstrates reproducing MRN/DOB fields, contradicting the redaction requirements. Replace it with clearly synthetic, de-identified content and avoid showing identifier reproduction.

Also applies to: 87-89

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@kits/clinical-note-red-flag-scanner/README.md` around lines 67 - 69, Replace
the clinicalNote example in the README with clearly synthetic, non-identifying
content that does not resemble real patient data or include names, demographics,
dates of birth, MRNs, or other identifiers. Update the related example at the
referenced reproduction section as well, removing any demonstration of
identifier reproduction while preserving the red-flag scanner usage context.

105-116: 🔒 Security & Privacy | 🟠 Major

Remove treatment and triage advice from the example output.

The sample recommends medication dosing and emergency-care instructions, while the system contract permits documentation-only remediation. Revise the example to use actions such as documenting missing fields, not treatment or return-to-ED guidance.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@kits/clinical-note-red-flag-scanner/README.md` around lines 105 - 116, Update
the example output entries FLAG-003 and FLAG-004 in the README so their
recommendation text only instructs users to document missing clinical fields or
plan details. Remove medication dosing guidance and emergency-care or
return-to-ED instructions while preserving the existing finding context.

73-80: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Align the documented response shape with the runtime contract.

This section says result contains a JSON object and shows the report without the outer result field, while the flow and agent documentation define result as a JSON string. Show the actual wrapper and serialization, or change the implementation and all documentation consistently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@kits/clinical-note-red-flag-scanner/README.md` around lines 73 - 80, Update
the “Example Output” section to match the runtime contract: show the outer
result field and represent its value as the serialized JSON string returned by
the flow. Keep the documented summary and flagCount payload consistent with the
implementation and related flow/agent documentation.
♻️ Duplicate comments (1)
kits/clinical-note-red-flag-scanner/flows/clinical-note-red-flag-scanner.ts (1)

114-114: 🩺 Stability & Availability | 🟠 Major

Enforce the documented maximum note size.

The runtime accepts arbitrarily large notes while the documentation promises a 10,000-token limit. Add bounded validation or chunking before the single LLM request.

  • kits/clinical-note-red-flag-scanner/flows/clinical-note-red-flag-scanner.ts#L114-L114: add a maximum-size guard or chunking path to the trigger contract.
  • kits/clinical-note-red-flag-scanner/agent.md#L33-L33: document the enforced limit and oversized-input behavior.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@kits/clinical-note-red-flag-scanner/flows/clinical-note-red-flag-scanner.ts`
at line 114, Enforce the documented 10,000-token maximum in the clinical note
trigger contract around the advance_schema definition by adding bounded
validation or chunking before the single LLM request. In
kits/clinical-note-red-flag-scanner/flows/clinical-note-red-flag-scanner.ts:114,
reject or appropriately process oversized clinicalNote values; in
kits/clinical-note-red-flag-scanner/agent.md:33, document the enforced limit and
the behavior for oversized input.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@kits/clinical-note-red-flag-scanner/prompts/clinical-note-red-flag-scanner_llmnode-453_system_0.md`:
- Line 13: Update the REGULATORY guidance in the system prompt to require
jurisdiction and care setting before making jurisdiction-specific findings. When
those inputs are unavailable, limit findings to requirements explicitly
identified by the caller or clinical note and label them non-jurisdictional.

In
`@kits/clinical-note-red-flag-scanner/prompts/clinical-note-red-flag-scanner_llmnode-453_user_1.md`:
- Line 4: Update the prompt input around clinicalNote so raw clinical notes
cannot be forwarded directly to Gemini without a data-control boundary. Require
and validate pre-redacted/de-identified content, or verify a compliant
zero-retention provider configuration before executing the node; otherwise block
execution rather than interpolating the complete note.

---

Outside diff comments:
In `@kits/clinical-note-red-flag-scanner/README.md`:
- Around line 67-69: Replace the clinicalNote example in the README with clearly
synthetic, non-identifying content that does not resemble real patient data or
include names, demographics, dates of birth, MRNs, or other identifiers. Update
the related example at the referenced reproduction section as well, removing any
demonstration of identifier reproduction while preserving the red-flag scanner
usage context.
- Around line 105-116: Update the example output entries FLAG-003 and FLAG-004
in the README so their recommendation text only instructs users to document
missing clinical fields or plan details. Remove medication dosing guidance and
emergency-care or return-to-ED instructions while preserving the existing
finding context.
- Around line 73-80: Update the “Example Output” section to match the runtime
contract: show the outer result field and represent its value as the serialized
JSON string returned by the flow. Keep the documented summary and flagCount
payload consistent with the implementation and related flow/agent documentation.

---

Duplicate comments:
In `@kits/clinical-note-red-flag-scanner/flows/clinical-note-red-flag-scanner.ts`:
- Line 114: Enforce the documented 10,000-token maximum in the clinical note
trigger contract around the advance_schema definition by adding bounded
validation or chunking before the single LLM request. In
kits/clinical-note-red-flag-scanner/flows/clinical-note-red-flag-scanner.ts:114,
reject or appropriately process oversized clinicalNote values; in
kits/clinical-note-red-flag-scanner/agent.md:33, document the enforced limit and
the behavior for oversized input.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fe830c49-c5c0-4bba-bc7e-97d970a0f9b7

📥 Commits

Reviewing files that changed from the base of the PR and between a56bd68 and dee8afb.

📒 Files selected for processing (6)
  • kits/clinical-note-red-flag-scanner/README.md
  • kits/clinical-note-red-flag-scanner/agent.md
  • kits/clinical-note-red-flag-scanner/flows/clinical-note-red-flag-scanner.ts
  • kits/clinical-note-red-flag-scanner/lamatic.config.ts
  • kits/clinical-note-red-flag-scanner/prompts/clinical-note-red-flag-scanner_llmnode-453_system_0.md
  • kits/clinical-note-red-flag-scanner/prompts/clinical-note-red-flag-scanner_llmnode-453_user_1.md

7. **FOLLOW_UP** — Missing follow-up plan, discharge instructions, or continuity-of-care documentation
8. **ASSESSMENT** — Missing or incomplete clinical assessment/diagnosis relative to documented symptoms
9. **IDENTITY** — Missing or incomplete patient identification markers (MRN, DOB, provider signature/attestation)
10. **REGULATORY** — Documentation gaps that may violate specific regulatory requirements (CMS, Joint Commission, state-level mandates, subject to applicable jurisdiction and care setting)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major

Mission-critical: require jurisdiction before regulatory findings.

The flow accepts only clinicalNote, so the model cannot reliably determine which CMS, Joint Commission, or state requirements apply. If jurisdiction and care setting are unavailable, restrict findings to requirements explicitly identified by the caller or note and label them non-jurisdictional.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@kits/clinical-note-red-flag-scanner/prompts/clinical-note-red-flag-scanner_llmnode-453_system_0.md`
at line 13, Update the REGULATORY guidance in the system prompt to require
jurisdiction and care setting before making jurisdiction-specific findings. When
those inputs are unavailable, limit findings to requirements explicitly
identified by the caller or clinical note and label them non-jurisdictional.

- Replace realistic PHI with synthetic placeholders in README example

- Strip remaining clinical advice from FLAG-003 and FLAG-004 examples in README

- Wrap JSON example output in stringified result field in README

- Enforce 45000 character limit in flow advance_schema

- Document enforced token limit and rejection behavior in agent.md

- Strengthen REGULATORY caveat in system prompt (advisory only, caller provides jurisdiction)

- Add hard PHI input contract to user prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant