Elffuss BraidHub

kikocis/llama-stack public

52eab8874aca · 952 BRawPermalink
1# Copyright (c) Meta Platforms, Inc. and affiliates.
2# All rights reserved.
3#
4# This source code is licensed under the terms described in the LICENSE file in
5# the root directory of this source tree.
6
7from termcolor import cprint
8
9from .base import ShieldResponse, TextShield
10
11
12class CodeScannerShield(TextShield):
13 async def run_impl(self, text: str) -> ShieldResponse:
14 from codeshield.cs import CodeShield
15
16 cprint(f"Running CodeScannerShield on {text[50:]}", color="magenta")
17 result = await CodeShield.scan_code(text)
18 if result.is_insecure:
19 return ShieldResponse(
20 is_violation=True,
21 violation_type=",".join(
22 [issue.pattern_id for issue in result.issues_found]
23 ),
24 violation_return_message="Sorry, I found security concerns in the code.",
25 )
26 else:
27 return ShieldResponse(is_violation=False)