Skip to main content

Guardrails for MSFT Agent Framework

Project description

HiddenLayer MSFT Agent Framework Guardrails

License Python 3.10+

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:

Related Projects

Project details


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

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file hiddenlayer_msft_agent_framework_guardrails-0.1.0.tar.gz.

File metadata

File hashes

Hashes for hiddenlayer_msft_agent_framework_guardrails-0.1.0.tar.gz
Algorithm Hash digest
SHA256 75abce4fa90170dd5a0335d95cbb512615e4b811e50b2780dd691c941cbf0943
MD5 935d51b0cff6c413f2801e553ae3a494
BLAKE2b-256 ccc73e6599111002908606614a887be0908444a9dda8f90614a450713a59d98b

See more details on using hashes here.

Provenance

The following attestation bundles were made for hiddenlayer_msft_agent_framework_guardrails-0.1.0.tar.gz:

Publisher: publish.yml on hiddenlayerai/hiddenlayer-msft-agent-framework-guardrails

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hiddenlayer_msft_agent_framework_guardrails-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hiddenlayer_msft_agent_framework_guardrails-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae693d9f1054c9d05f635636c2071ec39bc6cadff8caa21bb29c1cc6cb5d5eec
MD5 ea0b8fb4a91ba0cbdb59841f8bee88c2
BLAKE2b-256 ab78009bd1e9f4bc653021b399518fdd36785c753bc9cfb8b34ab10985c4aa48

See more details on using hashes here.

Provenance

The following attestation bundles were made for hiddenlayer_msft_agent_framework_guardrails-0.1.0-py3-none-any.whl:

Publisher: publish.yml on hiddenlayerai/hiddenlayer-msft-agent-framework-guardrails

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page