Skip to content

Python: Add Purview Middleware - #1142

Merged
dmytrostruk merged 15 commits into
microsoft:mainfrom
Rishabh4275:users/richawla/pythonPcOrch
Oct 16, 2025
Merged

Python: Add Purview Middleware#1142
dmytrostruk merged 15 commits into
microsoft:mainfrom
Rishabh4275:users/richawla/pythonPcOrch

Conversation

@Rishabh4275

Copy link
Copy Markdown
Contributor

Motivation and Context

Description

Adds Python Purview Middleware which adds Purview policy evaluation to the Microsoft Agent Framework. It lets you enforce data security / governance policies on both the prompt (user input + conversation history) and the model response before they proceed further in your workflow.
All changes are additive—no breaking changes to existing packages.

Follow-Up Opportunities

  1. Add caching for protection scope computations.
  2. Introduce higher-level policy decision aggregation object.
  3. Background Processing for flows that do not lead to a response, so shortcircuit
  4. Retry/backoff for 429 responses with telemetry counters.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings October 3, 2025 02:00
@markwallace-microsoft markwallace-microsoft added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Oct 3, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds Microsoft Purview integration to the Python Agent Framework, enabling data security and governance policy evaluation on conversational AI content. The implementation provides middleware that can block prompts or responses based on centrally managed Purview policies.

Key changes:

  • Complete Purview middleware integration with authentication, API clients, and content processing capabilities
  • Comprehensive model system using Pydantic for Microsoft Graph API interactions and policy evaluation
  • Full test coverage with extensive unit tests for all components and integration scenarios

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
python/samples/getting_started/purview_agent/ Sample application demonstrating Purview middleware usage with Azure OpenAI
python/packages/purview/tests/ Comprehensive test suite covering all middleware components and edge cases
python/packages/purview/pyproject.toml Package configuration with dependencies and development tools
python/packages/purview/agent_framework_purview/ Core implementation including models, client, processor, middleware, and settings
python/packages/purview/README.md Documentation with usage examples and configuration guidance
python/packages/purview/LICENSE MIT license for the package

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread python/packages/purview/agent_framework_purview/_settings.py Outdated
Comment thread python/packages/purview/agent_framework_purview/_processor.py Outdated
Comment thread python/packages/purview/agent_framework_purview/_processor.py
Comment thread python/packages/purview/agent_framework_purview/_client.py Outdated

@eavanvalkenburg eavanvalkenburg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no expert on the back and forth to and from Purview, so I haven't looked deeply at that. Overall I think the structure can be simplified, in python we tend to prefer less files even if they are longer, also the models folder is a concern, because even though it appears empty (because of the empty all) it will still be indexed by our api docs tooling. So please fix that. I also wonder about Agent vs ChatMiddleware for this, but it could even be both...

Comment thread python/packages/purview/pyproject.toml Outdated
Comment thread python/samples/getting_started/purview_agent/sample_purview_agent.py Outdated
Comment thread python/samples/getting_started/purview_agent/sample_purview_agent.py Outdated
Comment thread python/samples/getting_started/purview_agent/sample_purview_agent.py Outdated
Comment thread python/samples/getting_started/purview_agent/sample_purview_agent.py Outdated
Comment thread python/packages/purview/agent_framework_purview/models/content.py Outdated
Comment thread python/packages/purview/agent_framework_purview/_models.py Outdated
Comment thread python/packages/purview/agent_framework_purview/_client.py Outdated
Comment thread python/packages/purview/agent_framework_purview/_client.py Outdated
Comment thread python/packages/purview/agent_framework_purview/_settings.py Outdated
@Rishabh4275

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree company="Microsoft"

@microsoft-github-policy-service agree company="Microsoft"

@Rishabh4275
Rishabh4275 force-pushed the users/richawla/pythonPcOrch branch 2 times, most recently from 337acdd to 5687104 Compare October 9, 2025 03:08
@markwallace-microsoft

markwallace-microsoft commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework/azure
   _shared.py79791%135–136, 199, 202, 215, 217, 227
TOTAL10378166483% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
1352 98 💤 0 ❌ 0 🔥 27.945s ⏱️

@Rishabh4275
Rishabh4275 force-pushed the users/richawla/pythonPcOrch branch 2 times, most recently from e2bbd9d to 458ac54 Compare October 9, 2025 04:50
Comment thread python/packages/core/agent_framework/azure/_shared.py
@Rishabh4275

Copy link
Copy Markdown
Contributor Author

@eavanvalkenburg Could you have a look.
Thank you.

@Rishabh4275
Rishabh4275 force-pushed the users/richawla/pythonPcOrch branch 5 times, most recently from 6d225c7 to 4e4fc90 Compare October 9, 2025 07:38
Comment thread python/packages/purview/agent_framework_purview/_middleware.py
Comment thread python/packages/purview/agent_framework_purview/_middleware.py Outdated
Comment thread python/packages/purview/agent_framework_purview/_middleware.py Outdated
Comment thread python/packages/purview/agent_framework_purview/_middleware.py
Comment thread python/packages/purview/agent_framework_purview/_middleware.py Outdated
Comment thread python/packages/purview/pyproject.toml Outdated
Comment thread python/packages/purview/README.md Outdated
Comment thread python/samples/getting_started/purview_agent/README.md
Comment thread python/samples/getting_started/purview_agent/sample_purview_agent.py Outdated
Comment thread python/samples/getting_started/purview_agent/sample_purview_agent.py Outdated
@Rishabh4275
Rishabh4275 force-pushed the users/richawla/pythonPcOrch branch from 6988296 to aed9cf0 Compare October 15, 2025 23:05
@Rishabh4275
Rishabh4275 force-pushed the users/richawla/pythonPcOrch branch from 2f75be9 to 5af8391 Compare October 15, 2025 23:23
@dmytrostruk
dmytrostruk added this pull request to the merge queue Oct 16, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 16, 2025
@dmytrostruk
dmytrostruk added this pull request to the merge queue Oct 16, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 16, 2025
@dmytrostruk
dmytrostruk enabled auto-merge October 16, 2025 17:12
@dmytrostruk
dmytrostruk added this pull request to the merge queue Oct 16, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 16, 2025
@dmytrostruk
dmytrostruk enabled auto-merge October 16, 2025 20:37
@dmytrostruk
dmytrostruk disabled auto-merge October 16, 2025 20:39
@dmytrostruk
dmytrostruk marked this pull request as draft October 16, 2025 21:36
@dmytrostruk
dmytrostruk marked this pull request as ready for review October 16, 2025 21:46
@dmytrostruk
dmytrostruk added this pull request to the merge queue Oct 16, 2025
Merged via the queue into microsoft:main with commit 59da578 Oct 16, 2025
20 checks passed
ReubenBond pushed a commit to ReubenBond/agent-framework that referenced this pull request Oct 28, 2025
* [Py Purview] Purview Python Initial Commit

* [Py Purview] Purview Python Minor Fixes

* [Py Purview] Purview Python Comment Fixesish

* [Py Purview] Purview Python Agent Middleware Done

* [Py Purview] Purview Python Agent Middleware Done

* [Py Purview] Purview Python Lint Errors

* [Py Purview] Purview Python Final Hopefully

* [Py Purview] Purview Python Final Hopefully

* [Py Purview] Purview Python Fix ReadMe

* [Py Purview] Purview Python Fix MyPy

* [Py Purview] Purview Python Minor Updates on comments

* [Py Purview] Purview Python Fix Build Error

---------

Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com>
arisng pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
* [Py Purview] Purview Python Initial Commit

* [Py Purview] Purview Python Minor Fixes

* [Py Purview] Purview Python Comment Fixesish

* [Py Purview] Purview Python Agent Middleware Done

* [Py Purview] Purview Python Agent Middleware Done

* [Py Purview] Purview Python Lint Errors

* [Py Purview] Purview Python Final Hopefully

* [Py Purview] Purview Python Final Hopefully

* [Py Purview] Purview Python Fix ReadMe

* [Py Purview] Purview Python Fix MyPy

* [Py Purview] Purview Python Minor Updates on comments

* [Py Purview] Purview Python Fix Build Error

---------

Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants