Skip to content

Commit 7b0724b

Browse files
authored
Merge pull request #126 from ModusCreateOrg/ADE-66
[ADE-66] fix: enhance medical analysis instructions and enforce metadata integrity
2 parents e396e34 + 81d04d7 commit 7b0724b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

backend/src/document-processor/services/aws-bedrock.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ For lab values:
7272
- Set "isCritical" to true for urgent medical situations
7373
- Provide brief "conclusion" about what the value means for health
7474
- Add brief "suggestions" based on the value
75-
- If reference ranges are missing, add "reference-ranges-missing" to missingInformation and use standard ranges
75+
- IMPORTANT: For ANY lab value where reference/normal ranges are not explicitly stated in the document, you MUST add "reference-ranges-missing" to the missingInformation array and use standard medical ranges
76+
- If you use standard ranges because the document lacks them, clearly mark this in your response
7677
7778
CRITICAL FORMATTING RULES:
7879
- Begin immediately with { and end with }
@@ -87,6 +88,7 @@ Common errors to avoid:
8788
- Starting with "This appears to be a medical report..."
8889
- Creating nested JSON structures
8990
- Placing data inside definition fields
91+
- IMPORTANT: Failing to add "reference-ranges-missing" to missingInformation when ANY lab value lacks explicit ranges
9092
9193
Document text:
9294
`;

backend/src/services/perplexity.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';
22
import { ConfigService } from '@nestjs/config';
33
import axios from 'axios';
44
import { AwsSecretsService } from './aws-secrets.service';
5+
import { MedicalDocumentAnalysis } from 'src/document-processor/services/aws-bedrock.service';
56

67
export interface PerplexityMessage {
78
role: 'system' | 'user' | 'assistant';
@@ -275,11 +276,14 @@ export class PerplexityService {
275276
* @param originalText The original text of the medical document
276277
* @returns The corrected medical document analysis
277278
*/
278-
async reviewMedicalAnalysis(analysis: any, originalText: string): Promise<any> {
279+
async reviewMedicalAnalysis(
280+
analysis: MedicalDocumentAnalysis,
281+
originalText: string,
282+
): Promise<any> {
279283
this.logger.log('Reviewing medical document analysis with Perplexity');
280284

281285
const systemPrompt =
282-
'Medical information verification specialist. Verify analysis against trusted sources (Mayo Clinic, Cleveland Clinic, CDC, NIH, WHO, medical journals). Ensure accuracy of lab ranges, interpretations, and recommendations. Return only corrected JSON.';
286+
'Medical information verification specialist. Verify analysis against trusted sources (Mayo Clinic, Cleveland Clinic, CDC, NIH, WHO, medical journals). Ensure accuracy of lab ranges, interpretations, and recommendations. Return only corrected JSON. IMPORTANT: Do not modify the metadata object, especially preserve the metadata.missingInformation array exactly as provided.';
283287

284288
const analysisJson = JSON.stringify(analysis, null, 2);
285289

@@ -289,6 +293,7 @@ export class PerplexityService {
289293
`2. Interpretations of abnormal values\n` +
290294
`3. Medical conclusions and recommendations\n` +
291295
`4. Lab value categorizations\n\n` +
296+
`CRITICAL INSTRUCTION: Do NOT modify the metadata object. The metadata.missingInformation array must remain exactly as provided without any additions, removals, or changes.\n\n` +
292297
`Analysis JSON:\n${analysisJson}\n\n` +
293298
`Original Text:\n${originalText}\n\n` +
294299
`Return ONLY corrected JSON with identical structure. No preamble, explanation, or text before/after JSON.`;

0 commit comments

Comments
 (0)