0d3cb498a3
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
61 lines
2.1 KiB
JavaScript
61 lines
2.1 KiB
JavaScript
/**
|
|
* Transform Model Armor sanitization API response to Promptfoo guardrails format.
|
|
*
|
|
* This function maps the Model Armor filter results to Promptfoo's standardized
|
|
* guardrails response structure, enabling the `guardrails` assertion type.
|
|
*
|
|
* @see https://cloud.google.com/security-command-center/docs/sanitize-prompts-responses
|
|
*/
|
|
(function () {
|
|
const result = json.sanitizationResult || {};
|
|
const flagged = result.filterMatchState === 'MATCH_FOUND';
|
|
const filters = result.filterResults || {};
|
|
const reasons = [];
|
|
|
|
// Check RAI filters (Responsible AI: hate speech, harassment, dangerous, sexually explicit)
|
|
if (filters.rai?.raiFilterResult?.matchState === 'MATCH_FOUND') {
|
|
const raiResults = filters.rai.raiFilterResult.raiFilterTypeResults || {};
|
|
for (const key in raiResults) {
|
|
if (raiResults[key].matchState === 'MATCH_FOUND') {
|
|
reasons.push('RAI: ' + key.replace(/_/g, ' '));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Check prompt injection/jailbreak filter
|
|
if (filters.pi_and_jailbreak?.piAndJailbreakFilterResult?.matchState === 'MATCH_FOUND') {
|
|
const confidence = filters.pi_and_jailbreak.piAndJailbreakFilterResult.confidenceLevel || '';
|
|
reasons.push('Prompt Injection' + (confidence ? ' (' + confidence + ')' : ''));
|
|
}
|
|
|
|
// Check malicious URLs filter
|
|
if (filters.malicious_uris?.maliciousUriFilterResult?.matchState === 'MATCH_FOUND') {
|
|
reasons.push('Malicious URL');
|
|
}
|
|
|
|
// Check CSAM filter (always enabled, cannot be disabled)
|
|
if (filters.csam?.csamFilterResult?.matchState === 'MATCH_FOUND') {
|
|
reasons.push('CSAM');
|
|
}
|
|
|
|
// Check sensitive data filter (credit cards, SSNs, API keys, etc.)
|
|
if (filters.sdp?.sdpFilterResult?.inspectResult?.matchState === 'MATCH_FOUND') {
|
|
reasons.push('Sensitive Data');
|
|
}
|
|
|
|
const reasonStr = reasons.join('; ');
|
|
|
|
return {
|
|
output: flagged ? 'BLOCKED: ' + (reasonStr || 'Content flagged') : 'ALLOWED',
|
|
guardrails: {
|
|
flagged,
|
|
flaggedInput: flagged,
|
|
flaggedOutput: false,
|
|
reason: reasonStr || (flagged ? 'Content flagged by Model Armor' : ''),
|
|
},
|
|
metadata: {
|
|
modelArmor: result,
|
|
},
|
|
};
|
|
})();
|