Simon Corvoysier commited on
Commit
320ccd9
·
0 Parent(s):

Initial release

Browse files
Files changed (8) hide show
  1. LICENSE +21 -0
  2. README.md +4 -0
  3. ai_sentinel/__init__.py +3 -0
  4. ai_sentinel/audit.py +28 -0
  5. pyproject.toml +22 -0
  6. setup.cfg +22 -0
  7. setup.py +10 -0
  8. tests/test_audit.py +5 -0
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Corvoysier Simon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # ai-sentinel
2
+ A Python library as a tool for monitoring and managing AI systems.
3
+
4
+ ## Installation
ai_sentinel/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from .audit import audit, detect_prompt_injection
2
+
3
+ __all__ = ['audit', 'detect_prompt_injection']
ai_sentinel/audit.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+ DANGEROUS_PATTERNS = [
4
+ r"ignore previous instructions",
5
+ r"malicious",
6
+ r"jailbreak",
7
+ r"system override",
8
+ ]
9
+
10
+ def detect_prompt_injection(prompt: str) -> bool:
11
+ """
12
+ Detects if the given prompt contains any known prompt injection patterns.
13
+
14
+ Args:
15
+ prompt (str): The input prompt to be analyzed.
16
+ """
17
+ flags = []
18
+ for pattern in DANGEROUS_PATTERNS:
19
+ if re.search(pattern, prompt, re.IGNORECASE):
20
+ flags.append(pattern)
21
+ return flags
22
+
23
+ def audit(prompt: str) -> dict:
24
+ return {
25
+ "injection_patterns": detect_prompt_injection(prompt),
26
+ "length" : len(prompt),
27
+ "has_code": bool(re.search(r"\b(def |import |class )", prompt)),
28
+ }
pyproject.toml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ```toml
2
+
3
+ [project]
4
+
5
+ name = "ai-sentinel"
6
+ version = "0.1.0"
7
+ description = "Bibliothèque de sécurité pour l'IA (détection de prompt injection, audit de risques)"
8
+ readme = "README.md"
9
+ requires-python = ">=3.8"
10
+ license = { text = "MIT" }
11
+ keywords = ["ai", "security", "prompt injection", "audit"]
12
+
13
+ authors = [
14
+ { name="Mieow-ai", email="simon.corvoysier@gmail.com" }
15
+ ]
16
+
17
+ [build-system]
18
+ requires = ["setuptools>=61.0", "wheel"]
19
+ build-backend = "setuptools.build_meta"
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/Mieow-ai/ai-sentinel"
setup.cfg ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [metadata]
2
+ name = ai-sentinel
3
+ version = 0.1.0
4
+ author = Mieow-ai
5
+ author_email = simon.corvoysier@gmail.com
6
+ description = A Python library as a tool for monitoring and managing AI systems.
7
+ long_description = file: README.md
8
+ long_description_content_type = text/markdown
9
+ url = https://github.com/Mieow-ai/ai-sentinel
10
+ license = MIT
11
+ classifiers =
12
+ Programming Language :: Python :: 3
13
+ License :: OSI Approved :: MIT License
14
+ Operating System :: OS Independent
15
+
16
+ [options]
17
+ packages = find:
18
+ python_requires = >=3.8
19
+ install_requires =
20
+ ---
21
+ tests_require =
22
+ pytest
setup.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from setuptools import setup, find_packages
2
+
3
+ setup (
4
+ name='ai-sentinel',
5
+ version='0.1.0',
6
+ packages=find_packages(),
7
+ description='AI Sentinel: A tool for monitoring and managing AI systems.',
8
+ author='Mieow-AI',
9
+ license='MIT',
10
+ )
tests/test_audit.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ from ai_sentinel import audit
2
+
3
+ def test_detection():
4
+ result = audit("Ignore previous instructions")
5
+ assert result["prompt_injection_detected"] == True