Skip to content

Python: updated declarative samples and handling of non-pydantic response formats - #5022

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 3 commits into
microsoft:mainfrom
eavanvalkenburg:fix_declarative_samples
Apr 1, 2026
Merged

Python: updated declarative samples and handling of non-pydantic response formats#5022
Eduard van Valkenburg (eavanvalkenburg) merged 3 commits into
microsoft:mainfrom
eavanvalkenburg:fix_declarative_samples

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

Motivation and Context

Fixed the declarative samples and noticed that non-pydantic response formats (json schema definition) was not handled in the response types.
Fixed now across the board.

Description

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 April 1, 2026 08:57
@markwallace-microsoft Mark Wallace (markwallace-microsoft) added the python Usage: [Issues, PRs], Target: Python label Apr 1, 2026
@markwallace-microsoft

Mark Wallace (markwallace-microsoft) commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _agents.py4125287%461, 470, 525, 1020, 1065, 1138–1142, 1202, 1230, 1267, 1288, 1308–1309, 1314, 1361, 1403, 1425, 1427, 1440, 1446, 1491, 1493, 1502–1507, 1512, 1514, 1520–1521, 1528, 1530–1531, 1539–1540, 1543–1545, 1555–1560, 1564, 1569, 1571
   _clients.py137794%324, 375, 531–534, 649
   _tools.py9478890%190–191, 364, 366, 379, 404–406, 414, 432, 446, 453, 460, 483, 485, 492, 500, 539, 583, 587, 619–621, 623, 629, 674–676, 678, 701, 727, 731, 769–771, 775, 797, 909–915, 951, 963, 965, 967, 970–973, 994, 998, 1002, 1016–1018, 1359, 1381, 1468–1474, 1603, 1607, 1653, 1714–1715, 1830, 1850, 1852, 1908, 1971, 2143–2144, 2164, 2220–2221, 2281, 2359–2360, 2427, 2432, 2439
   _types.py10759091%58, 67–68, 122, 127, 146, 148, 152, 156, 158, 160, 162, 180, 184, 210, 232, 237, 242, 246, 276, 687–688, 847–848, 1233, 1305, 1340, 1360, 1370, 1422, 1554–1556, 1746, 1837–1842, 1867, 1955, 1961–1963, 1968, 2059, 2071, 2094, 2349, 2373, 2468, 2717, 2923, 2992, 3003, 3005–3009, 3011, 3014–3022, 3032, 3236–3238, 3241–3243, 3247, 3252, 3256, 3340–3342, 3371, 3448–3452
packages/declarative/agent_framework_declarative
   _loader.py2535877%574, 576, 603–613, 655–658, 661–663, 666, 668–670, 673, 681, 698–703, 755–760, 778–783, 791, 793, 798, 801–804, 807–808, 811–812, 826–827, 857
packages/ollama/agent_framework_ollama
   _chat_client.py208995%396, 398, 409, 413–414, 422, 433, 512, 518
packages/openai/agent_framework_openai
   _chat_client.py85512785%520–523, 527–528, 533–534, 544–545, 552, 567–573, 594, 602, 625, 743, 842, 901, 903, 905, 907, 973, 987, 1067, 1077, 1082, 1125, 1202, 1232, 1289, 1382, 1387, 1391–1393, 1397–1398, 1464, 1493, 1499, 1509, 1515, 1520, 1526, 1531–1532, 1593, 1615–1616, 1631–1632, 1650–1651, 1692–1695, 1857, 1895–1896, 1912, 1914, 1992–2000, 2122, 2157, 2172, 2192–2202, 2215, 2226–2230, 2244, 2258–2269, 2278, 2310–2313, 2321–2322, 2324–2326, 2340–2342, 2352–2353, 2359, 2374
TOTAL26994318788% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
5341 20 💤 0 ❌ 0 🔥 1m 28s ⏱️

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 updates Python declarative samples and extends structured output handling so response_format values provided as runtime JSON schema mappings (dicts) are preserved and parsed into response.value across multiple chat clients.

Changes:

  • Update declarative samples/YAML to align with Foundry environment variables and loader defaults.
  • Propagate non-Pydantic response_format mappings through core response types so JSON text is parsed into dict values.
  • Add/adjust tests across providers (OpenAI, Azure OpenAI, Foundry, Anthropic, Ollama, core) to cover dict response_format parsing.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
python/samples/05-end-to-end/evaluation/foundry_evals/evaluate_tool_calls_sample.py Minor sample instruction string formatting.
python/samples/04-hosting/a2a/a2a_agent_as_function_tools.py Minor formatting of env var error message.
python/samples/02-agents/declarative/openai_agent.py Use create_agent_from_yaml_path instead of manual YAML loading.
python/samples/02-agents/declarative/microsoft_learn_agent.py Add explanatory module-level documentation for the sample.
python/samples/02-agents/declarative/inline_yaml.py Update sample env var guidance and inline YAML to Foundry model variable.
python/packages/openai/tests/openai/test_openai_chat_completion_client.py Add test coverage for dict response_format parsing; update integration expectations.
python/packages/openai/tests/openai/test_openai_chat_client.py Add runtime JSON schema mapping parsing-path test; update integration expectations.
python/packages/openai/tests/openai/test_openai_chat_client_azure.py Update integration expectations for runtime JSON schema parsing.
python/packages/openai/agent_framework_openai/_chat_client.py Preserve non-Pydantic response_format on ChatResponse for parsing.
python/packages/ollama/tests/test_ollama_chat_client.py Add test for dict response_format parsing.
python/packages/ollama/agent_framework_ollama/_chat_client.py Thread response_format through Ollama parsing to enable JSON parsing.
python/packages/foundry/tests/foundry/test_foundry_chat_client.py Add parsing-path test; update integration expectations.
python/packages/declarative/agent_framework_declarative/_loader.py Update provider mapping and change default_provider to Foundry.
python/packages/core/tests/core/test_types.py Add core type tests for mapping response_format parsing (sync + streaming).
python/packages/core/tests/core/test_observability.py Ensure streaming finalizer passes through mapping response_format.
python/packages/core/tests/core/test_agents.py Add agent-level tests for mapping response_format propagation/parsing.
python/packages/core/tests/core/conftest.py Ensure test streaming clients pass through mapping response_format.
python/packages/core/agent_framework/_types.py Add mapping structured format support and JSON parsing for value.
python/packages/core/agent_framework/_tools.py Pass mapping response_format through streaming finalizer path.
python/packages/core/agent_framework/_evaluation.py Minor formatting tweaks.
python/packages/core/agent_framework/_clients.py Pass mapping response_format into ChatResponse.from_updates.
python/packages/core/agent_framework/_agents.py Preserve mapping response_format when constructing AgentResponse.
python/packages/anthropic/tests/test_anthropic_client.py Add test ensuring dict response_format is preserved for parsing.
agent-samples/foundry/MicrosoftLearnAgent.yaml Update env var names to FOUNDRY_* conventions.

Comment thread python/samples/02-agents/declarative/inline_yaml.py Outdated
Comment thread python/samples/02-agents/declarative/microsoft_learn_agent.py
Comment thread python/packages/declarative/agent_framework_declarative/_loader.py
Comment thread python/packages/core/agent_framework/_types.py Outdated
Comment thread python/packages/openai/agent_framework_openai/_chat_client.py
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Apr 1, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 1, 2026
Merged via the queue into microsoft:main with commit 519bb0c Apr 1, 2026
31 checks passed
@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) deleted the fix_declarative_samples branch June 30, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants