Skip to content

Use additionalProperties for homogeneous dict schemas#1738

Merged
alexmojaki merged 8 commits intomainfrom
compact-homogeneous-dict-schema
Mar 3, 2026
Merged

Use additionalProperties for homogeneous dict schemas#1738
alexmojaki merged 8 commits intomainfrom
compact-homogeneous-dict-schema

Conversation

@adriangb
Copy link
Copy Markdown
Member

@adriangb adriangb commented Feb 26, 2026

Summary

Use tiered dict schema generation based on key count and key length to balance schema detail vs size:

  • Small dicts (≤10 keys): Always use per-key properties for maximum detail
  • Medium dicts (11–100 keys): Use additionalProperties when homogeneous (all values same schema), per-key properties when heterogeneous
  • Large dicts (>100 keys or any key >100 chars): Use additionalProperties when homogeneous, drop schema entirely ({'type': 'object'}) when heterogeneous to avoid excessively large schemas

Extracts _check_homogeneous() helper for clarity.

Test plan

  • Updated test_homogeneous_dict_schema — small dicts now use per-key properties
  • Added test_medium_dict_schema — medium homogeneous/heterogeneous/plain cases
  • Added test_large_dict_schema — large homogeneous → additionalProperties, large heterogeneous → schema dropped
  • Added test_long_key_dict_schema — long keys treated same as large dicts
  • Updated parametrized and recursive test snapshots
  • Updated OpenAI integration test snapshots
  • Pyright passes clean

🤖 Generated with Claude Code

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>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Feb 26, 2026

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

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

View logs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@alexmojaki
Copy link
Copy Markdown
Collaborator

pls unmark as draft when ready to face devin. general idea sounds good.

Co-authored-by: Alex Hall <alex.mojaki@gmail.com>
@adriangb adriangb marked this pull request as ready for review February 26, 2026 16:07
@adriangb
Copy link
Copy Markdown
Member Author

pls unmark as draft when ready to face devin. general idea sounds good.

done marked as ready

devin-ai-integration[bot]

This comment was marked as resolved.

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>
devin-ai-integration[bot]

This comment was marked as resolved.

adriangb and others added 2 commits February 27, 2026 11:55
… 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>
@adriangb adriangb requested a review from alexmojaki February 27, 2026 12:12
Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 3, 2026

@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.

Copilot AI and others added 2 commits March 3, 2026 14:04
…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>
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 9 additional findings in Devin Review.

Open in Devin Review

@alexmojaki alexmojaki merged commit ac3f23b into main Mar 3, 2026
24 checks passed
@alexmojaki alexmojaki deleted the compact-homogeneous-dict-schema branch March 3, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants