Skip to content

3.1.1 hotfix: tighten extraction.highlights strict-validation contract - #42

Merged
tyler5673 merged 1 commit into
mainfrom
dx-724-python-sdk-3-1-1-internal-max-tokens
Aug 12, 2026
Merged

3.1.1 hotfix: tighten extraction.highlights strict-validation contract#42
tyler5673 merged 1 commit into
mainfrom
dx-724-python-sdk-3-1-1-internal-max-tokens

Conversation

@tyler5673

Copy link
Copy Markdown
Contributor

Summary

Forward-compat tightening of extraction.highlights. 3.1.0 carried a small set of knobs on the user-facing ExtractionHighlights model that the server doesn't currently accept; 3.1.1 keeps the same extra="forbid" runtime behaviour but trims the public surface to an empty container so callers can't accidentally route an unsupported parameter to the server.

The extraction.highlights sub-object is the canonical forward-compat slot for future sub-fields. Unknown keys still raise pydantic.ValidationError locally on both the model instance form and the dict form, mirroring the server's strict extraction schema.

Files

File Change
pyproject.toml version = "3.1.0"3.1.1
src/youdotcom/models/extraction.py Drop the empty-config-field from ExtractionHighlightsTypedDict; ExtractionHighlights is now an empty container. Module- and class-level docstrings are forward-compat only.
src/youdotcom/sdk.py One comment touch-up (no behaviour change).
tests/test_extraction.py Drop the four max_tokens-specific tests. New test_extraction_unsupported_highlights_key_raises_locally covers the strict-validation path an end-user would now hit.
tests/test_live.py Drop test_highlights_with_max_tokens (the field no longer exists).
tests/test_performance.py Drop the max_tokens=1000 knob from the highlights-metric call.
CHANGELOG.md New [3.1.1] - 2026-08-12 section above the 3.1.0 entry.
MIGRATION.md Trim the max_tokens rows from the migration table and the dict example.
docs/models/extraction.md Update the highlights row of the field table to reflect the empty container.

Mirror on docs PR #307

The same fix is mirrored as a one-line edit on the docs PR branch (Su-Sea/youdotcom-docs PR #307, commit e384e0e): the extraction.highlights.max_tokens row in the parameter table on /docs/guides/retrieve-page-content is replaced with a forward-compat container entry.

Validation

  • mypy clean on src/youdotcom/ (81 files).

  • 34 / 34 tests in tests/test_extraction.py pass.

  • Full non-mockserver test suite: 208 pass; 78 mockserver-only fails are unchanged from 3.1.0 (CI runs mockserver and these turn green on b7eb08a and on this branch).

  • Wheel smoke in a fresh venv: Extraction.model_validate({"extraction_mode": "highlights", "highlights": {"max_tokens": 1000}}) raises ValidationError; valid inputs still round-trip with empty highlights.

  • Live prod smoke through the existing ~/Workspace/Temp/youdotcom-sdk-3.1.0-smoke/ venv against prod with the prod YDC_API_KEY:

    • extraction={"extraction_mode": "highlights"}results.web[].contents.highlights returned in 0.78 s.
    • Extraction(extraction_mode=FULL_PAGE, full_page=...) — full-page Markdown returned in 1.20 s.

Out of scope

  • No release to PyPI yet — this PR is the draft the user asked for. PyPI publish happens after approval.
  • Docs PR #307 already merged into dy-723-… (d903a6be384e0e).

Forward-compat tightening of the `extraction.highlights` sub-object:

- The Pydantic model and TypedDict no longer expose any sub-fields at
  the user-facing API surface; unknown keys (typos, unsupported knobs)
  continue to be rejected with `pydantic.ValidationError` (`extra="forbid"`
  was already in place; the prior version carried an internal knob that
  should not have been part of the public contract). Both the model
  instance form and the dict form are validated, mirroring the server's
  strict `extraction` schema.
- `ExtractionHighlights` is kept as an empty container so that the
  dict shape stays stable for future sub-fields; callers continue to
  write `extraction={"extraction_mode": "highlights"}` without
  depending on a future field.
- Tests, docs (MIGRATION, extraction model page, parameter table in
  `search-retrieve-page-content.mdx`), and the changelog are aligned
  with the new public surface.

User-visible change: callers passing the previously-exposed internal
knob will now get a fast, local `ValidationError` (instead of silently
sending the field to the server). All other behavior is unchanged.

Validation:
- mypy clean (81 source files).
- 34 / 34 tests in `tests/test_extraction.py` pass.
- Full non-mockserver test suite: 208 pass (78 mockserver-only fails
  are unchanged from 3.1.0; CI runs mockserver and turns them green).
- Wheel smoke: `Extraction.model_validate({"extraction_mode":
  "highlights", "highlights": {"max_tokens": 1000}})` raises
  ValidationError; valid inputs still round-trip.
- Live prod smoke: highlights + full_page against prod still return
  expected shapes.

Refs: forward-compat tightening (no Linear issue; requested by
product). Mirrors docs PR #307 follow-up that drops the equivalent
table row in `youdotcom-docs/fern/pages/search-retrieve-page-content.mdx`.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@tyler5673 tyler5673 added the bug Something isn't working label Aug 12, 2026
@factory-droid

factory-droid Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Droid encountered an error —— View job


Droid is reviewing code and running a security check…

@tyler5673
tyler5673 marked this pull request as ready for review August 12, 2026 18:09
@factory-droid

factory-droid Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Droid finished @tyler5673's task —— View job


LGTM — no high-confidence, actionable issues found.

@tyler5673
tyler5673 merged commit 8e4ced6 into main Aug 12, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant