# Sentinel Python SDK
[](https://pypi.org/project/sentinel-sdk/)
[](https://github.com/swayam8624/Sentinel/blob/main/LICENSE)
[](https://pypi.org/project/sentinel-sdk/)
Python SDK for Sentinel - A self-healing LLM firewall with cryptographic data protection.
## Overview
The Sentinel Python SDK provides a secure interface to LLM providers through the Sentinel security pipeline. It acts as a drop-in replacement for popular LLM SDKs while adding enterprise-grade security features including:
- Real-time data redaction and tokenization
- Format-preserving encryption (FF3-1)
- Semantic violation detection
- Constitutional AI reflection
- Prompt rewriting and ranking
- Tool/function call guarding
## Installation
```bash
pip install sentinel-sdk
```
## Quick Start
### Basic Usage
```python
from sentinel import SentinelClient
# Initialize the client
client = SentinelClient(
base_url="http://localhost:8080",
api_key="your-api-key"
)
# Send a chat completion request through Sentinel
response = client.chat_completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "Hello, world!"}
]
)
print(response.choices[0].message.content)
```
### Advanced Usage
```python
from sentinel import SentinelClient
# Initialize with custom configuration
client = SentinelClient(
base_url="http://localhost:8080",
api_key="your-api-key",
timeout=60
)
# Sanitize a prompt before sending to LLM
sanitized = client.sanitize_prompt("Process sensitive data: 123-45-6789")
print(f"Sanitized prompt: {sanitized['sanitizedPrompt']}")
# Process an LLM response for security
response = "Here's the sensitive information: 123-45-6789"
processed = client.process_response(response)
print(f"Processed response: {processed['processedResponse']}")
```
## Features
### 🔐 Data Protection
- Real-time data redaction/tokenization
- Format-preserving encryption (FF3-1)
- Reversible detokenization with policy gating
- Multi-language PII detection
### 🛡️ Self-Healing Security
- Semantic violation detection
- Constitutional AI reflection
- Prompt rewriting and ranking
- Tool/function call guarding
### 🔌 Provider Compatibility
- Drop-in replacement for OpenAI SDK
- Support for all major LLM providers
- Streaming support with mid-stream inspection
- Multi-tenant policy management
### ⚙️ Advanced Configuration
- Policy engine integration
- Custom security rules
- Audit trails and compliance reporting
- Observability with metrics and tracing
## API Reference
### SentinelClient
#### `__init__(base_url, api_key, timeout)`
Initialize the Sentinel client.
**Parameters:**
- `base_url` (str): The base URL for the Sentinel gateway (default: "http://localhost:8080")
- `api_key` (str, optional): API key for authentication
- `timeout` (int): Request timeout in seconds (default: 30)
#### `sanitize_prompt(prompt)`
Sanitize a prompt before sending to LLM.
**Parameters:**
- `prompt` (str): The prompt to sanitize
**Returns:**
- `dict`: Sanitized prompt and metadata
#### `process_response(response)`
Process an LLM response for security.
**Parameters:**
- `response` (str): The LLM response to process
**Returns:**
- `dict`: Processed response and metadata
#### `configure_policies(policies)`
Configure security policies.
**Parameters:**
- `policies` (dict): Policy configuration
**Returns:**
- `dict`: Policy update result
### ChatCompletions
#### `create(model, messages, temperature, max_tokens, **kwargs)`
Create a chat completion through the Sentinel gateway.
**Parameters:**
- `model` (str): The model to use
- `messages` (list): List of message dictionaries
- `temperature` (float, optional): Sampling temperature
- `max_tokens` (int, optional): Maximum tokens to generate
- `**kwargs`: Additional parameters
**Returns:**
- `dict`: Chat completion response
## Configuration
### Environment Variables
- `SENTINEL_BASE_URL`: Default base URL for the Sentinel gateway
- `SENTINEL_API_KEY`: Default API key for authentication
- `SENTINEL_TIMEOUT`: Default request timeout in seconds
### Configuration File
You can also configure the client using a configuration file:
```python
import os
from sentinel import SentinelClient
# Load configuration from environment
client = SentinelClient(
base_url=os.getenv("SENTINEL_BASE_URL", "http://localhost:8080"),
api_key=os.getenv("SENTINEL_API_KEY"),
timeout=int(os.getenv("SENTINEL_TIMEOUT", "30"))
)
```
## Error Handling
The SDK raises standard Python exceptions:
```python
from sentinel import SentinelClient
import requests
client = SentinelClient(base_url="http://localhost:8080")
try:
response = client.chat_completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello"}]
)
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
except Exception as e:
print(f"An error occurred: {e}")
```
## Examples
### Multi-tenant Usage
```python
from sentinel import SentinelClient
# Different clients for different tenants
tenant_a_client = SentinelClient(
base_url="http://localhost:8080",
api_key="tenant-a-key"
)
tenant_b_client = SentinelClient(
base_url="http://localhost:8080",
api_key="tenant-b-key"
)
```
### Custom Policy Configuration
```python
from sentinel import SentinelClient
client = SentinelClient(base_url="http://localhost:8080")
# Configure custom policies
policies = {
"pii_detection": {
"enabled": True,
"languages": ["en", "es", "fr"],
"action": "tokenize"
},
"prompt_filtering": {
"enabled": True,
"threshold": 0.75
}
}
result = client.configure_policies(policies)
print(f"Policies configured: {result['success']}")
```
## Integration with Popular Frameworks
### LangChain Integration
```python
from langchain.llms import Sentinel
from langchain.prompts import PromptTemplate
llm = Sentinel(
base_url="http://localhost:8080",
api_key="your-api-key"
)
template = "What is {subject}?"
prompt = PromptTemplate.from_template(template)
chain = prompt | llm
response = chain.invoke({"subject": "artificial intelligence"})
print(response)
```
### LlamaIndex Integration
```python
from llama_index.llms import Sentinel
from llama_index import VectorStoreIndex, SimpleDirectoryReader
llm = Sentinel(
base_url="http://localhost:8080",
api_key="your-api-key"
)
documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents, llm=llm)
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")
print(response)
```
## Development
### Installation from Source
```bash
git clone https://github.com/swayam8624/Sentinel.git
cd Sentinel/sdk/python
pip install -e .
```
### Running Tests
```bash
pip install pytest
pytest tests/
```
### Code Formatting
```bash
pip install black flake8
black .
flake8 .
```
## Documentation
For full documentation, visit [https://swayam8624.github.io/Sentinel/](https://swayam8624.github.io/Sentinel/)
## Support
For issues, feature requests, or questions, please [open an issue](https://github.com/swayam8624/Sentinel/issues) on GitHub.
## License
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": "https://github.com/swayam8624/Sentinel",
"name": "yugenkairo-sentinel-sdk",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "sentinel, llm, security, firewall, cryptography, pii, data-protection",
"author": "Sentinel Team",
"author_email": "sentinel-team@example.com",
"download_url": "https://files.pythonhosted.org/packages/fa/a6/53ef643355dafad179dff1ac2a7cc658599c16c52b7bc4838065cb0fe56c/yugenkairo_sentinel_sdk-0.1.1.tar.gz",
"platform": null,
"description": "# Sentinel Python SDK\n\n[](https://pypi.org/project/sentinel-sdk/)\n[](https://github.com/swayam8624/Sentinel/blob/main/LICENSE)\n[](https://pypi.org/project/sentinel-sdk/)\n\nPython SDK for Sentinel - A self-healing LLM firewall with cryptographic data protection.\n\n## Overview\n\nThe Sentinel Python SDK provides a secure interface to LLM providers through the Sentinel security pipeline. It acts as a drop-in replacement for popular LLM SDKs while adding enterprise-grade security features including:\n\n- Real-time data redaction and tokenization\n- Format-preserving encryption (FF3-1)\n- Semantic violation detection\n- Constitutional AI reflection\n- Prompt rewriting and ranking\n- Tool/function call guarding\n\n## Installation\n\n```bash\npip install sentinel-sdk\n```\n\n## Quick Start\n\n### Basic Usage\n\n```python\nfrom sentinel import SentinelClient\n\n# Initialize the client\nclient = SentinelClient(\n base_url=\"http://localhost:8080\",\n api_key=\"your-api-key\"\n)\n\n# Send a chat completion request through Sentinel\nresponse = client.chat_completions.create(\n model=\"gpt-3.5-turbo\",\n messages=[\n {\"role\": \"user\", \"content\": \"Hello, world!\"}\n ]\n)\n\nprint(response.choices[0].message.content)\n```\n\n### Advanced Usage\n\n```python\nfrom sentinel import SentinelClient\n\n# Initialize with custom configuration\nclient = SentinelClient(\n base_url=\"http://localhost:8080\",\n api_key=\"your-api-key\",\n timeout=60\n)\n\n# Sanitize a prompt before sending to LLM\nsanitized = client.sanitize_prompt(\"Process sensitive data: 123-45-6789\")\nprint(f\"Sanitized prompt: {sanitized['sanitizedPrompt']}\")\n\n# Process an LLM response for security\nresponse = \"Here's the sensitive information: 123-45-6789\"\nprocessed = client.process_response(response)\nprint(f\"Processed response: {processed['processedResponse']}\")\n```\n\n## Features\n\n### \ud83d\udd10 Data Protection\n\n- Real-time data redaction/tokenization\n- Format-preserving encryption (FF3-1)\n- Reversible detokenization with policy gating\n- Multi-language PII detection\n\n### \ud83d\udee1\ufe0f Self-Healing Security\n\n- Semantic violation detection\n- Constitutional AI reflection\n- Prompt rewriting and ranking\n- Tool/function call guarding\n\n### \ud83d\udd0c Provider Compatibility\n\n- Drop-in replacement for OpenAI SDK\n- Support for all major LLM providers\n- Streaming support with mid-stream inspection\n- Multi-tenant policy management\n\n### \u2699\ufe0f Advanced Configuration\n\n- Policy engine integration\n- Custom security rules\n- Audit trails and compliance reporting\n- Observability with metrics and tracing\n\n## API Reference\n\n### SentinelClient\n\n#### `__init__(base_url, api_key, timeout)`\n\nInitialize the Sentinel client.\n\n**Parameters:**\n\n- `base_url` (str): The base URL for the Sentinel gateway (default: \"http://localhost:8080\")\n- `api_key` (str, optional): API key for authentication\n- `timeout` (int): Request timeout in seconds (default: 30)\n\n#### `sanitize_prompt(prompt)`\n\nSanitize a prompt before sending to LLM.\n\n**Parameters:**\n\n- `prompt` (str): The prompt to sanitize\n\n**Returns:**\n\n- `dict`: Sanitized prompt and metadata\n\n#### `process_response(response)`\n\nProcess an LLM response for security.\n\n**Parameters:**\n\n- `response` (str): The LLM response to process\n\n**Returns:**\n\n- `dict`: Processed response and metadata\n\n#### `configure_policies(policies)`\n\nConfigure security policies.\n\n**Parameters:**\n\n- `policies` (dict): Policy configuration\n\n**Returns:**\n\n- `dict`: Policy update result\n\n### ChatCompletions\n\n#### `create(model, messages, temperature, max_tokens, **kwargs)`\n\nCreate a chat completion through the Sentinel gateway.\n\n**Parameters:**\n\n- `model` (str): The model to use\n- `messages` (list): List of message dictionaries\n- `temperature` (float, optional): Sampling temperature\n- `max_tokens` (int, optional): Maximum tokens to generate\n- `**kwargs`: Additional parameters\n\n**Returns:**\n\n- `dict`: Chat completion response\n\n## Configuration\n\n### Environment Variables\n\n- `SENTINEL_BASE_URL`: Default base URL for the Sentinel gateway\n- `SENTINEL_API_KEY`: Default API key for authentication\n- `SENTINEL_TIMEOUT`: Default request timeout in seconds\n\n### Configuration File\n\nYou can also configure the client using a configuration file:\n\n```python\nimport os\nfrom sentinel import SentinelClient\n\n# Load configuration from environment\nclient = SentinelClient(\n base_url=os.getenv(\"SENTINEL_BASE_URL\", \"http://localhost:8080\"),\n api_key=os.getenv(\"SENTINEL_API_KEY\"),\n timeout=int(os.getenv(\"SENTINEL_TIMEOUT\", \"30\"))\n)\n```\n\n## Error Handling\n\nThe SDK raises standard Python exceptions:\n\n```python\nfrom sentinel import SentinelClient\nimport requests\n\nclient = SentinelClient(base_url=\"http://localhost:8080\")\n\ntry:\n response = client.chat_completions.create(\n model=\"gpt-3.5-turbo\",\n messages=[{\"role\": \"user\", \"content\": \"Hello\"}]\n )\nexcept requests.exceptions.RequestException as e:\n print(f\"Request failed: {e}\")\nexcept Exception as e:\n print(f\"An error occurred: {e}\")\n```\n\n## Examples\n\n### Multi-tenant Usage\n\n```python\nfrom sentinel import SentinelClient\n\n# Different clients for different tenants\ntenant_a_client = SentinelClient(\n base_url=\"http://localhost:8080\",\n api_key=\"tenant-a-key\"\n)\n\ntenant_b_client = SentinelClient(\n base_url=\"http://localhost:8080\",\n api_key=\"tenant-b-key\"\n)\n```\n\n### Custom Policy Configuration\n\n```python\nfrom sentinel import SentinelClient\n\nclient = SentinelClient(base_url=\"http://localhost:8080\")\n\n# Configure custom policies\npolicies = {\n \"pii_detection\": {\n \"enabled\": True,\n \"languages\": [\"en\", \"es\", \"fr\"],\n \"action\": \"tokenize\"\n },\n \"prompt_filtering\": {\n \"enabled\": True,\n \"threshold\": 0.75\n }\n}\n\nresult = client.configure_policies(policies)\nprint(f\"Policies configured: {result['success']}\")\n```\n\n## Integration with Popular Frameworks\n\n### LangChain Integration\n\n```python\nfrom langchain.llms import Sentinel\nfrom langchain.prompts import PromptTemplate\n\nllm = Sentinel(\n base_url=\"http://localhost:8080\",\n api_key=\"your-api-key\"\n)\n\ntemplate = \"What is {subject}?\"\nprompt = PromptTemplate.from_template(template)\nchain = prompt | llm\n\nresponse = chain.invoke({\"subject\": \"artificial intelligence\"})\nprint(response)\n```\n\n### LlamaIndex Integration\n\n```python\nfrom llama_index.llms import Sentinel\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader\n\nllm = Sentinel(\n base_url=\"http://localhost:8080\",\n api_key=\"your-api-key\"\n)\n\ndocuments = SimpleDirectoryReader(\"data\").load_data()\nindex = VectorStoreIndex.from_documents(documents, llm=llm)\nquery_engine = index.as_query_engine()\n\nresponse = query_engine.query(\"What did the author do growing up?\")\nprint(response)\n```\n\n## Development\n\n### Installation from Source\n\n```bash\ngit clone https://github.com/swayam8624/Sentinel.git\ncd Sentinel/sdk/python\npip install -e .\n```\n\n### Running Tests\n\n```bash\npip install pytest\npytest tests/\n```\n\n### Code Formatting\n\n```bash\npip install black flake8\nblack .\nflake8 .\n```\n\n## Documentation\n\nFor full documentation, visit [https://swayam8624.github.io/Sentinel/](https://swayam8624.github.io/Sentinel/)\n\n## Support\n\nFor issues, feature requests, or questions, please [open an issue](https://github.com/swayam8624/Sentinel/issues) on GitHub.\n\n## License\n\nThis project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.\n",
"bugtrack_url": null,
"license": null,
"summary": "Python SDK for Sentinel - A self-healing LLM firewall with cryptographic data protection",
"version": "0.1.1",
"project_urls": {
"Documentation": "https://swayam8624.github.io/Sentinel/",
"Homepage": "https://github.com/swayam8624/Sentinel",
"Source": "https://github.com/swayam8624/Sentinel",
"Tracker": "https://github.com/swayam8624/Sentinel/issues"
},
"split_keywords": [
"sentinel",
" llm",
" security",
" firewall",
" cryptography",
" pii",
" data-protection"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "2c079be12227ae5e397b9d79f2e89d90289168c089946f8997f4d558e71ad3ea",
"md5": "46bcdfa9021ead74ecadc1c9bbf33a31",
"sha256": "0f46975c8ec6bd36cad1c5f6f7e6a5ed117b50cef58a82ba05cf9f3a5783ac12"
},
"downloads": -1,
"filename": "yugenkairo_sentinel_sdk-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "46bcdfa9021ead74ecadc1c9bbf33a31",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 9112,
"upload_time": "2025-08-29T18:25:17",
"upload_time_iso_8601": "2025-08-29T18:25:17.582621Z",
"url": "https://files.pythonhosted.org/packages/2c/07/9be12227ae5e397b9d79f2e89d90289168c089946f8997f4d558e71ad3ea/yugenkairo_sentinel_sdk-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "faa653ef643355dafad179dff1ac2a7cc658599c16c52b7bc4838065cb0fe56c",
"md5": "cd9251e8741170fc23606b98bcd9a216",
"sha256": "e4b3328336abd17a4803e414c5d2de43d5fa76815d575aebde558644bd7c254d"
},
"downloads": -1,
"filename": "yugenkairo_sentinel_sdk-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "cd9251e8741170fc23606b98bcd9a216",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9985,
"upload_time": "2025-08-29T18:25:18",
"upload_time_iso_8601": "2025-08-29T18:25:18.704372Z",
"url": "https://files.pythonhosted.org/packages/fa/a6/53ef643355dafad179dff1ac2a7cc658599c16c52b7bc4838065cb0fe56c/yugenkairo_sentinel_sdk-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-29 18:25:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "swayam8624",
"github_project": "Sentinel",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "yugenkairo-sentinel-sdk"
}