fix: AdCP responses now properly omit null/empty optional fields #638
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.
Problem
The AdCP JSON schema does not allow null values for optional fields. According to the spec, optional fields should be omitted entirely, not set to null or empty values.
Issues:
ListAuthorizedPropertiesResponsewas explicitly settingerrors=[], causing it to be included in responsesAdCPBaseModel.model_dump()wasn't usingexclude_none=Trueby defaultExample of incorrect behavior:
{ "publisher_domains": ["example.com"], "errors": [], // ❌ Should be omitted "primary_channels": null // ❌ Should be omitted }Correct behavior:
{ "publisher_domains": ["example.com"] // ✅ Optional fields omitted }Root Causes
1. Missing
exclude_noneinAdCPBaseModel.model_dump()AdCPBaseModeldidn't setexclude_none=Trueby default, so None-valued fields were included in serialization.2. Incorrect override in
ListAuthorizedPropertiesResponse.model_dump()Lines 3444-3446 in schemas.py were converting
errors=Nonetoerrors=[]:3. Explicit
errors=[]in tool codesrc/core/tools/properties.pyline 202 was settingerrors=[]explicitly, causing it to be included even though it had no errors.Solution
1. Added
model_dump()toAdCPBaseModelNow all AdCP response models automatically omit None-valued optional fields.
2. Fixed
ListAuthorizedPropertiesResponse.model_dump()Removed the override that was converting None to []. Now delegates to parent:
3. Removed explicit
errors=[]from tool codeProperties tool no longer sets
errors=[]when there are no errors.Testing
✅ 48/48 AdCP contract tests passing
✅ 829/829 unit tests passing
✅ Updated 4 unit tests to verify omission behavior
✅ Updated 1 integration test to verify MCP/A2A parity with new behavior
Tests now verify:
Impact
Breaking Change:⚠️ Clients expecting all optional fields to be present (even with null/empty values) will need to handle omitted fields.
Benefits:
Scope:
AdCPBaseModelListAuthorizedPropertiesResponseresponsesFiles Changed
src/core/schemas.py (2 changes)
model_dump()override toAdCPBaseModelwithexclude_none=TrueListAuthorizedPropertiesResponse.model_dump()to delegate to parentsrc/core/tools/properties.py (1 change)
errors=[]assignmenttests/unit/test_adcp_contract.py (4 test updates)
tests/unit/test_authorized_properties.py (2 test updates)
tests/integration/test_a2a_response_compliance.py (1 test update)
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com