Use additionalProperties for homogeneous dict schemas#1738
Merged
alexmojaki merged 8 commits intomainfrom Mar 3, 2026
Merged
Conversation
When all values in a dict have the same JSON schema, use a compact `additionalProperties` representation instead of listing per-key `properties`. This mirrors how arrays use `items` vs `prefixItems`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Deploying logfire-docs with
|
| Latest commit: |
d9739ff
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://bd84bcdc.logfire-docs.pages.dev |
| Branch Preview URL: | https://compact-homogeneous-dict-sch.logfire-docs.pages.dev |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
|
pls unmark as draft when ready to face devin. general idea sounds good. |
alexmojaki
reviewed
Feb 26, 2026
Co-authored-by: Alex Hall <alex.mojaki@gmail.com>
Member
Author
done marked as ready |
Small dicts (≤10 keys) always use per-key properties for maximum detail. Medium dicts (11-100 keys) use additionalProperties when homogeneous, per-key properties when heterogeneous. Large dicts (>100 keys or any key >100 chars) use additionalProperties when homogeneous, or drop the schema entirely when heterogeneous to avoid excessively large schemas. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… path Use >10 keys so the test actually hits the additionalProperties code path instead of falling into the small-dict per-key properties path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Pass the schema dict (containing properties/additionalProperties) to _format_items for plain dicts instead of None, so nested values get their type-specific formatting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
alexmojaki
reviewed
Feb 27, 2026
Contributor
|
@alexmojaki I've opened a new pull request, #1750, to work on those changes. Once the pull request is ready, I'll request review from you. |
…opilot setup steps (#1750) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexmojaki <3627481+alexmojaki@users.noreply.github.com>
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
Use tiered dict schema generation based on key count and key length to balance schema detail vs size:
propertiesfor maximum detailadditionalPropertieswhen homogeneous (all values same schema), per-keypropertieswhen heterogeneousadditionalPropertieswhen homogeneous, drop schema entirely ({'type': 'object'}) when heterogeneous to avoid excessively large schemasExtracts
_check_homogeneous()helper for clarity.Test plan
test_homogeneous_dict_schema— small dicts now use per-key propertiestest_medium_dict_schema— medium homogeneous/heterogeneous/plain casestest_large_dict_schema— large homogeneous → additionalProperties, large heterogeneous → schema droppedtest_long_key_dict_schema— long keys treated same as large dicts🤖 Generated with Claude Code