docs: add guide on validating Actor input with Pydantic#941
Draft
vdusek wants to merge 2 commits into
Draft
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #941 +/- ##
=======================================
Coverage 86.87% 86.87%
=======================================
Files 48 48
Lines 2942 2942
=======================================
Hits 2556 2556
Misses 386 386
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Adds a new guide on validating Actor input with Pydantic, so Actor code works with a typed, guaranteed-valid object instead of reaching into a raw input dictionary. Follows the structure of the existing scraping-library guides.
What's included
docs/03_guides/10_pydantic.mdx— the guide: why raw-dict access is fragile, defining an input model (aliases bridgingcamelCase↔snake_case, defaults, constraints, a custom validator,extra='ignore'), validating withmodel_validateand failing fast onValidationError, the relationship to the platform input schema, and a few extra Pydantic features (HttpUrl/EmailStr,model_validator,SecretStr).docs/03_guides/code/10_pydantic.py— the runnable example Actor, shown viaRunnableCodeBlock(Run on Apify) like the other guides. It validates the input, logs the normalized values, and stores them asOUTPUT.Verification
OUTPUT(exit 0); invalid input logs a per-field summary (errors referenced by their input-schema aliases) and the run endsFAILED.ruff check,ruff format --check, andty checkpass.Numbered
10to sit after the in-progress uv (#932,08) and Scrapling (#938,09) guides.