Guardrails for MSFT Agent Framework
Project description
HiddenLayer MSFT Agent Framework Guardrails
HiddenLayer MSFT Agent Framework Guardrails provides AI safety middleware for the Azure Agent Framework, enabling real-time detection and mitigation of malicious inputs, prompt injections, and unsafe AI agent behaviors.
Features
- Input Scanning: Analyze user messages for prompt injections and malicious content
- Output Filtering: Monitor and filter AI-generated responses
- Redaction Support: Automatically redact sensitive or unsafe content
- Streaming Compatible: Works with both streaming and non-streaming responses
- Easy Integration: Simple middleware integration with Azure Agent Framework
Installation
pip install hiddenlayer-msft-agent-framework-guardrails
Configuration
Set the following environment variables:
# Required: Your HiddenLayer API credentials
export HIDDENLAYER_API_ID="your-api-id"
export HIDDENLAYER_API_KEY="your-api-key"
# Optional: Project-specific configuration
export HIDDENLAYER_PROJECT_ID="your-project-id"
export HIDDENLAYER_REQUESTER_ID="your-app-name"
Usage
Basic Example
import asyncio
from agent_framework.openai import OpenAIChatClient
from hiddenlayer_msft_agent_framework_guardrails.middleware import (
HiddenlayerChatMiddleware,
HiddenLayerParams,
)
# Configure HiddenLayer parameters
params = HiddenLayerParams(model="gpt-4o-mini")
async def main():
# Create agent with HiddenLayer guardrails
agent = OpenAIChatClient().as_agent(
name="MyAgent",
model="gpt-4o-mini",
instructions="You are a helpful assistant.",
middleware=[
HiddenlayerChatMiddleware(params),
],
)
# Run query
query = "Hello!"
print(f"User: {query}")
result = await agent.run(query)
print(f"Result: {result}")
if __name__ == "__main__":
asyncio.run(main())
Advanced Examples
Streaming Responses
async def streaming_example():
agent = OpenAIChatClient().as_agent(
name="MyAgent",
instructions="You are a helpful assistant.",
middleware=[
HiddenlayerChatMiddleware(params),
],
)
query = "Hello!"
print(f"User: {query}")
print("Agent: ", end="", flush=True)
async for chunk in agent.run(query, stream=True):
if chunk.text:
print(chunk.text, end="", flush=True)
print()
Capability Matrix
| Alert | Block | Redact | |
|---|---|---|---|
| Input Guardrails | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Output Guardrails | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Streaming Output Guardrails | :white_check_mark: | :x: | :x: |
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Support
For issues, questions, or contributions:
- GitHub Issues: Report a bug or request a feature
- Email: sdks@hiddenlayer.com
Related Projects
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters