-
Notifications
You must be signed in to change notification settings - Fork 761
Allow failures when PII guardrail fails, manage blank agents in requests #1277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good implementation of flexible PII guardrail handling and agent management. Found a few areas for improvement around error handling and test cleanup.
const result = await piiHandler(context, params, 'beforeRequestHook'); | ||
console.log('result', result); | ||
expect(result.error).toBeNull(); | ||
expect(result.verdict).toBe(true); | ||
expect(result.transformed).toBe(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Dead Code
Issue: Console.log statements left in test code
Fix: Remove debug console.log statements before production
Impact: Cleaner test output and better code hygiene
const result = await piiHandler(context, params, 'beforeRequestHook'); | |
console.log('result', result); | |
expect(result.error).toBeNull(); | |
expect(result.verdict).toBe(true); | |
expect(result.transformed).toBe(false); | |
const result = await piiHandler(context, params, 'beforeRequestHook'); | |
expect(result.error).toBeNull(); | |
expect(result.verdict).toBe(true); | |
expect(result.transformed).toBe(false); |
const result = await piiHandler( | ||
mockContext, | ||
{ ...params, redact: false }, | ||
'beforeRequestHook' | ||
); | ||
console.log('result', result); | ||
expect(result.error).toBeNull(); | ||
expect(result.verdict).toBe(false); | ||
expect(result.transformed).toBe(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Dead Code
Issue: Console.log statements left in test code
Fix: Remove debug console.log statements before production
Impact: Cleaner test output and better code hygiene
const result = await piiHandler( | |
mockContext, | |
{ ...params, redact: false }, | |
'beforeRequestHook' | |
); | |
console.log('result', result); | |
expect(result.error).toBeNull(); | |
expect(result.verdict).toBe(false); | |
expect(result.transformed).toBe(false); | |
const result = await piiHandler( | |
mockContext, | |
{ ...params, redact: false }, | |
'beforeRequestHook' | |
); | |
expect(result.error).toBeNull(); | |
expect(result.verdict).toBe(false); | |
expect(result.transformed).toBe(false); |
try { | ||
const response = await redact(documents, parameters, options); | ||
const response = await redact(documents, parameters, pluginOptions); | ||
data = response.results.documents; | ||
if (parameters.redact) { | ||
const containsPII = | ||
data.length > 0 && data.some((doc: any) => doc.entities.length > 0); | ||
if (containsPII) { | ||
verdict = false; | ||
} | ||
if (parameters.redact && containsPII) { | ||
const redactedData = (response.results.documents ?? []).map( | ||
(doc: any) => doc.redactedText | ||
); | ||
setCurrentContentPart(context, eventType, transformedData, redactedData); | ||
transformed = true; | ||
verdict = true; | ||
} | ||
} catch (e) { | ||
error = e; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Code Refactor
Issue: Missing error handling for malformed Azure API responses
Fix: Add validation for response structure before accessing nested properties
Impact: Prevents runtime crashes when Azure API returns unexpected response format
try { | |
const response = await redact(documents, parameters, options); | |
const response = await redact(documents, parameters, pluginOptions); | |
data = response.results.documents; | |
if (parameters.redact) { | |
const containsPII = | |
data.length > 0 && data.some((doc: any) => doc.entities.length > 0); | |
if (containsPII) { | |
verdict = false; | |
} | |
if (parameters.redact && containsPII) { | |
const redactedData = (response.results.documents ?? []).map( | |
(doc: any) => doc.redactedText | |
); | |
setCurrentContentPart(context, eventType, transformedData, redactedData); | |
transformed = true; | |
verdict = true; | |
} | |
} catch (e) { | |
error = e; | |
try { | |
const response = await redact(documents, parameters, pluginOptions); | |
if (!response?.results?.documents) { | |
throw new Error('Invalid response format from Azure PII API'); | |
} | |
data = response.results.documents; | |
const containsPII = | |
data.length > 0 && data.some((doc: any) => doc.entities?.length > 0); | |
if (containsPII) { | |
verdict = false; | |
} | |
if (parameters.redact && containsPII) { | |
const redactedData = (response.results.documents ?? []).map( | |
(doc: any) => doc.redactedText | |
); | |
setCurrentContentPart(context, eventType, transformedData, redactedData); | |
transformed = true; | |
verdict = true; | |
} | |
} catch (e) { | |
error = e; |
Important PR Review SkippedPR review skipped as per the configuration setting. Run a manually review by commenting /matter review 💡Tips to use Matter AICommand List
|
No description provided.