ace-ai
Version:
ACE SDK for generating synthetic data and ensuring security and compliance with PII and HIPAA regulations. Includes MCP server protection.
198 lines (168 loc) β’ 8.46 kB
JavaScript
// Healthcare AI Chatbot Demo using ACE SDK
// This demo showcases how the ACE SDK protects against security risks in a healthcare AI application
const ace = require('./');
// Initialize the ACE SDK client
const client = new ace.Client();
// Demo function to simulate processing user input in a healthcare chatbot
function processHealthcareChat(message, userData = {}, destinationCountry = 'US') {
console.log('\n=== Healthcare AI Chatbot Processing ===');
console.log(`User Message: "${message}"`);
console.log(`User Data: ${JSON.stringify(userData)}\n`);
// 1. Password and Secret Detection
console.log('--- 1. Password and Secret Detection ---');
const hasSecrets = client.scanForSecrets(message);
if (hasSecrets) {
console.log('π¨ SECURITY ALERT: Secrets/passwords detected in user input!');
console.log('β Blocking processing to prevent credential leakage.');
return { status: 'blocked', reason: 'secrets_detected' };
} else {
console.log('β
No secrets detected in user input.');
}
// 2. Client/Host App Layer Protection
console.log('\n--- 2. Client/Host App Layer Protection ---');
const request = { message, userData };
const isRequestSafe = client.protectMCPHost(request);
if (!isRequestSafe) {
console.log('π¨ SECURITY ALERT: Unsafe request detected!');
console.log('β Blocking request to protect host application.');
return { status: 'blocked', reason: 'unsafe_request' };
} else {
console.log('β
Request passed host protection checks.');
}
// 3. PII/HIPAA Data Handling
console.log('\n--- 3. PII/HIPAA Data Handling ---');
const hasPII = client.containsPII(message);
const hasHIPAA = client.containsHIPAA(message);
if (hasPII || hasHIPAA) {
console.log('β οΈ PII/HIPAA data detected in user input.');
console.log('π Sanitizing data before further processing...');
const sanitizedMessage = client.sanitizeText(message);
console.log(`π Original message: "${message}"`);
console.log(`β
Sanitized message: "${sanitizedMessage}"`);
message = sanitizedMessage; // Use sanitized message for further processing
} else {
console.log('β
No PII/HIPAA data detected in user input.');
}
// 4. US Data Residency Enforcement
console.log('\n--- 4. US Data Residency Enforcement ---');
// Simulate sending data to a remote service
const canSendData = client.ensureUSDataResidency(message, destinationCountry);
if (!canSendData) {
console.log(`π¨ DATA RESIDENCY VIOLATION: Attempting to send HIPAA data to ${destinationCountry}!`);
console.log('β Blocking data transfer to maintain compliance.');
return { status: 'blocked', reason: 'data_residency_violation' };
} else {
if (destinationCountry !== 'US' && client.containsHIPAA(message)) {
console.log('β οΈ HIPAA data would be blocked from leaving the US, but destination is compliant.');
} else if (destinationCountry === 'US') {
console.log('β
Destination is US, data residency requirements satisfied.');
} else {
console.log('β
No HIPAA data detected, no residency restrictions apply.');
}
}
// 5. Prevention of Sensitive Data Passing to LLMs
console.log('\n--- 5. Prevention of Sensitive Data Passing to LLMs ---');
const llmValidation = client.validateDataBeforeLLM(message);
if (!llmValidation.isValid) {
console.log('π¨ VALIDATION ERROR: Invalid data for LLM processing!');
console.log(`β Error: ${llmValidation.error}`);
return { status: 'blocked', reason: 'invalid_llm_data' };
}
if (llmValidation.warning) {
console.log(`β οΈ ${llmValidation.warning}`);
console.log('β
Data has been sanitized before sending to LLM.');
console.log(`π Sanitized data: "${llmValidation.sanitizedData}"`);
message = llmValidation.sanitizedData; // Use sanitized data for LLM processing
} else {
console.log('β
Data validated successfully for LLM processing.');
}
// Simulate LLM processing with protected data
console.log('\nπ€ Simulating LLM Response Generation...');
const llmResponse = generateLLMResponse(message);
console.log(`π¬ LLM Response: "${llmResponse}"`);
return { status: 'success', response: llmResponse };
}
// Simple mock function to simulate LLM response generation
function generateLLMResponse(input) {
// In a real implementation, this would call an actual LLM API
const responses = [
"I understand your concern. Let me provide some general information.",
"Based on what you've shared, here's some helpful advice.",
"Thank you for sharing that information. Here's what I recommend.",
"I can help with that. Here's some relevant information.",
"That's an important topic. Here's what you should know."
];
// Simple selection based on input length
const index = input.length % responses.length;
return responses[index];
}
// Run the demo
console.log('π₯ Healthcare AI Chatbot Security Demo');
console.log('========================================');
// Demo 1: Safe interaction
console.log('\nπ Demo 1: Safe User Interaction');
processHealthcareChat("I'd like to know more about managing diabetes.");
// Demo 2: Password/Secret Detection
console.log('\nπ Demo 2: Password/Secret Detection');
processHealthcareChat("My password is supersecret123 and my API key is sk-abc123xyz789.");
// Demo 3: PII/HIPAA Data Handling
console.log('\nπ‘οΈ Demo 3: PII/HIPAA Data Handling');
processHealthcareChat("I have a heart condition and take medication daily.");
// Demo 4: US Data Residency Enforcement
console.log('\nπΊπΈ Demo 4: US Data Residency Enforcement');
console.log('Testing with HIPAA data going to EU (should be blocked):');
const hipaaMessage = "Patient has diabetes and takes insulin.";
const canSendToEU = client.ensureUSDataResidency(hipaaMessage, 'EU');
if (!canSendToEU) {
console.log('π¨ SIMULATED BLOCK: HIPAA data blocked from leaving the US to EU!');
} else {
console.log('β
Data can be sent to EU');
}
console.log('\nTesting with non-HIPAA data going to EU (should be allowed):');
const nonHipaaMessage = "I'd like to learn about nutrition.";
const canSendNonHIPAAToEU = client.ensureUSDataResidency(nonHipaaMessage, 'EU');
if (!canSendNonHIPAAToEU) {
console.log('π¨ Data blocked from leaving the US');
} else {
console.log('β
Non-HIPAA data can be sent to EU');
}
// Demo 5: Unsafe Host Request with Secrets
console.log('\nπ‘οΈ Demo 5: Unsafe Host Request Protection (Secrets)');
const requestWithSecrets = {
message: "Here is my database password: dbpassword123",
userData: {}
};
console.log('\n=== Healthcare AI Chatbot Processing (Request with Secrets) ===');
console.log(`User Message: "${requestWithSecrets.message}"`);
console.log(`User Data: ${JSON.stringify(requestWithSecrets.userData)}\n`);
console.log('--- Client/Host App Layer Protection ---');
const isRequestSafe = client.protectMCPHost(requestWithSecrets);
if (!isRequestSafe) {
console.log('π¨ SECURITY ALERT: Unsafe request detected!');
console.log('β Blocking request to protect host application.');
} else {
console.log('β
Request passed host protection checks.');
}
// Demo 6: Unsafe Host Request with PII
console.log('\nπ‘οΈ Demo 6: Unsafe Host Request Protection (PII)');
const requestWithPII = {
message: "Patient info: John Doe, age 35",
userData: {}
};
console.log('\n=== Healthcare AI Chatbot Processing (Request with PII) ===');
console.log(`User Message: "${requestWithPII.message}"`);
console.log(`User Data: ${JSON.stringify(requestWithPII.userData)}\n`);
console.log('--- Client/Host App Layer Protection ---');
const isRequestSafePII = client.protectMCPHost(requestWithPII);
if (!isRequestSafePII) {
console.log('π¨ SECURITY ALERT: Unsafe request detected!');
console.log('β Blocking request to protect host application.');
} else {
console.log('β
Request passed host protection checks.');
}
console.log('\nπ Summary of ACE SDK Security Features:');
console.log('1. π Password and Secret Detection - Prevents credential leakage');
console.log('2. π‘οΈ Client/Host App Protection - Validates incoming requests');
console.log('3. π§Ό PII/HIPAA Handling - Detects and sanitizes sensitive data');
console.log('4. πΊπΈ US Data Residency - Ensures HIPAA data stays in the US');
console.log('5. π€ LLM Data Protection - Prevents sensitive data from reaching LLMs');