Python: [BREAKING] Redesign Python exception hierarchy#4082
Merged
eavanvalkenburg merged 3 commits intomicrosoft:mainfrom Feb 19, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements a comprehensive redesign of the Python exception hierarchy to replace the flat ServiceException family with domain-scoped exception branches. This provides callers with precise exception targets and clear error semantics.
Changes:
- Redesigned exception hierarchy with domain-specific branches (Agent, ChatClient, Integration, Workflow, Content, Tool, Middleware)
- Removed old flat
ServiceExceptionfamily and replaced with semantically meaningful exceptions - Migrated initialization validation errors to use built-in Python exceptions (
ValueError,TypeError,RuntimeError) - Consolidated workflow exceptions from
_workflows/_exceptions.pyinto mainexceptions.py - Updated comprehensive documentation in
CODING_STANDARD.mdwith hierarchy diagrams, design principles, and usage guidance
Reviewed changes
Copilot reviewed 87 out of 87 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| python/packages/core/agent_framework/exceptions.py | Complete redesign of exception hierarchy with 6 domain branches, each with consistent suberror patterns |
| python/CODING_STANDARD.md | Comprehensive documentation of new hierarchy including design rationale, full tree diagram, and usage guide |
| python/packages/core/agent_framework/_workflows/_exceptions.py | Deleted - workflow exceptions moved to main exceptions.py |
| python/packages/core/agent_framework/workflows/*.py | Updated imports to use exceptions from main module instead of local _exceptions.py |
| python/packages/core/agent_framework/init.py | Workflow imports changed from single _workflows import to individual submodule imports; workflow exceptions now exported from main exceptions module |
| python/packages/core/agent_framework/openai/* | ServiceInitializationError → ValueError; ServiceInvalidRequestError → ChatClientInvalidRequestException; ServiceResponseException → ChatClientException |
| python/packages/core/agent_framework/azure/* | Same pattern as OpenAI - init errors → ValueError, runtime errors → ChatClient* exceptions |
| python/packages/redis/agent_framework_redis/_context_provider.py | ServiceInitializationError → ValueError; ServiceInvalidRequestError → IntegrationInvalidRequestException |
| python/packages/mem0/agent_framework_mem0/_context_provider.py | ServiceInitializationError → ValueError for filter validation |
| python/packages/purview/agent_framework_purview/_exceptions.py | PurviewServiceError now inherits from IntegrationException; PurviewAuthenticationError from IntegrationInvalidAuthException |
| python/packages/ollama/agent_framework_ollama/_chat_client.py | ServiceInvalidRequestError → ChatClientInvalidRequestException; ServiceResponseException → ChatClientException |
| python/packages/foundry_local/agent_framework_foundry_local/_foundry_local_client.py | ServiceInitializationError → ValueError for model validation |
| python/packages/declarative/agent_framework_declarative/_workflows/_executors_agents.py | AgentInvocationError removed; replaced with AgentInvalidRequestException (not found) and AgentInvalidResponseException (invocation failure) |
| python/packages/declarative/agent_framework_declarative/_workflows/_factory.py | DeclarativeWorkflowError now inherits from WorkflowException |
| python/packages/declarative/agent_framework_declarative/_workflows/_actions_error.py | WorkflowActionError now inherits from WorkflowException |
| python/packages/declarative/agent_framework_declarative/_loader.py | DeclarativeLoaderError now inherits from AgentException (was AgentFrameworkException) |
| python/packages/github_copilot/agent_framework_github_copilot/_agent.py | ServiceException → AgentException; client not initialized → RuntimeError |
| python/packages/copilotstudio/agent_framework_copilotstudio/* | ServiceException → AgentException; ServiceInitializationError → ValueError |
| python/packages/claude/agent_framework_claude/_agent.py | ServiceException → AgentException; client not initialized → RuntimeError |
| python/packages/azure-ai/agent_framework_azure_ai/* | ServiceInitializationError → ValueError; ServiceInvalidRequestError → IntegrationInvalidRequestException |
| python/packages/bedrock/agent_framework_bedrock/_chat_client.py | ServiceInitializationError → ValueError; ServiceInvalidResponseError → ChatClientInvalidResponseException |
| python/packages/anthropic/agent_framework_anthropic/_chat_client.py | ServiceInitializationError → ValueError for missing API key |
| All test files | Updated to expect new exception types; ValueError for validation, domain-specific exceptions for runtime failures |
f62042c to
a66f2e3
Compare
Member
dmytrostruk
approved these changes
Feb 19, 2026
TaoChenOSU
reviewed
Feb 19, 2026
TaoChenOSU
approved these changes
Feb 19, 2026
Replace the flat ServiceException family with domain-scoped branches: - AgentException (with InvalidAuth, InvalidRequest, InvalidResponse, ContentFilter) - ChatClientException (same consistent suberrors) - IntegrationException (same + InitializationError) - WorkflowException (Runner, Convergence, Checkpoint, Validation, Action, Declarative) - ContentError (AdditionItemMismatch) - ToolException / ToolExecutionException (unchanged) - MiddlewareException / MiddlewareTermination (unchanged) Key changes: - All Service* exceptions removed (ServiceException, ServiceInitializationError, etc.) - AgentExecutionException split into AgentInvalidRequest/ResponseException - AgentInvocationError removed, split into AgentInvalidRequest/ResponseException - Workflow exceptions moved from _workflows/_exceptions.py into main exceptions.py - _workflows/__init__.py emptied; main __init__.py imports directly from submodules - Purview exceptions re-parented under IntegrationException hierarchy - Init validation errors use built-in ValueError/TypeError instead of custom exceptions - CODING_STANDARD.md updated with hierarchy design and rationale Fixes microsoft#3410 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ToolException: base class for all tool-related exceptions (preconditions, connection/init failures). ToolExecutionException: runtime call failures (tool call failed, reconnect failed, MCP errors). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- azurefunctions: _context.py, _app.py, _serialization.py, test_func_utils.py used 'from agent_framework._workflows import X' which broke after emptying _workflows/__init__.py; changed to direct submodule imports - azure-ai-search: test still referenced ServiceInitializationError; updated to ValueError to match production code Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0baee84 to
bc3d923
Compare
dmytrostruk
approved these changes
Feb 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the flat
ServiceExceptionfamily with domain-scoped exception branches, giving callers preciseexcepttargets and clear error semantics.Fixes #3410
New Hierarchy
Breaking Changes
ServiceException,ServiceInitializationError,ServiceResponseException,ServiceContentFilterException,ServiceInvalidAuthError,ServiceInvalidExecutionSettingsError,ServiceInvalidRequestError,ServiceInvalidResponseErrorAgentExecutionException(split →AgentInvalidRequestException/AgentInvalidResponseException)AgentInvocationError(split →AgentInvalidRequestException/AgentInvalidResponseException)AgentInitializationError,AgentSessionException,ChatClientInitializationError(0 callsites)CheckpointDecodingError(merged →WorkflowCheckpointException)IntegrationExceptionhierarchyWorkflowException(moved from_workflows/_exceptions.pytoexceptions.py)ValueError/TypeErrorinstead of custom exceptionsDesign Principles
ValueError/TypeErrorfor config checks; AF exceptions only for domain-level failuresexcept AgentFrameworkExceptioncatches everythingOther Changes
_workflows/__init__.pyemptied; main__init__.pyimports directly from submodulesCODING_STANDARD.mdupdated with hierarchy design, rationale, and branch selection guide