Checking your account

You can read the lesson while its saved answers and constructions load. Learning controls will open once that work is ready.

Python Validation and Error Handling

Check a Note and Default the Copy Count

Coding challenges

BOTIE

Return the original request when its note is text or null. Return "note is missing" when the key is absent.
Ready to test
0 passed · 0 failed · 3 not run

An empty floor. Start with the information your machine needs.

Received result

Your answer will arrive here.

Examples, experiments and workspace controls
Live values

Connect a tool's inputs to see what it produces. You can try a branch before connecting it to Result.

Try your own inputs

Use a copy of the example to try your own data. Keep the problem's assumptions in mind, and predict the effect of a change before checking the output. You can also add another branch to compare two ways of doing the calculation.

Start at an output arrow, then click or drag to an input. Drag empty space to pan. Delete removes a selection. Ctrl/Cmd+Z undoes a change.
Context for this challenge

Return the original request when its note is text or null. Return "note is missing" when the key is absent.

A report request must include note, even when the sender chooses null, meaning no note. If copies is absent, use 1. The supplied titles are already valid text.

Inspect the component calculation
Check one request field(
  Request: Report request
  Field: note
  Presence: required
  Allowed value: text or null
)
Examples and results
Report request
title
Inspection notes
note
null
Required result
title
Inspection notes
note
null
Report request
title
Morning report
note
Check page two
copies
3
Required result
title
Morning report
note
Check page two
copies
3
Report request
title
Draft report
note
""
copies
0
Required result
title
Draft report
note
""
copies
0
Try a fresh construction

This clears this draft, including its undo history. Earlier successful attempts stay recorded. Build again without opening hints to record an independent attempt.

Stuck? Inspect a worked construction

The tools below form one possible solution. You can assemble it, follow its signals, and undo that change to return to your own construction.

Assumptions and test precision

These pieces demonstrate selected field rules. They do not run Pydantic. JSON null represents Python None; the Python challenges check the full model. Numerical tests allow a difference of 0.001. Lists and structures must also have the right shape.

Your last tested pieces can start the full construction. An existing draft there keeps its own pieces.

The Note Contains a Number

This check uses the pieces from “Keep Missing and Null Different”.

BOTIE

The next sender supplies note:17 and copies:2. Keep the same required text-or-null note rule.
Report request
title
Evening report
note
17
copies
2
Does note:17 satisfy the required text-or-null rule?

Saving your prediction runs your current construction on these inputs and checks the earlier examples too.

Build a construction in the workspace above first. This case will test those pieces.

Which setting allows a supplied null without permitting an absent note?

Declare requiredness separately from the allowed values.

These pieces demonstrate selected field rules. They do not run Pydantic. JSON null represents Python None; the Python challenges check the full model.

Continue the coursePydantic Constraints and Validators →
← Fail Fast, Fail Early