Styxis
Company
Knowledge

Pydantic MISSING unions: checking that a parent response does not disclose child fields

Validate the public field set independently of the runtime object's available information. That keeps the agreed disclosure boundary visible.

Pydantic MISSING unions: checking that a parent response does not disclose child fields

Declaring a parent response type does not by itself demonstrate that every child-only attribute is excluded from publication. If a type combination used for missingness changes serialization behavior, inspect emitted paths directly. Checking that valid parent fields exist is different from checking that extra fields are absent. [1, 2, 3]

What the primary source establishes

A report describes child fields being serialized instead of respecting a declared parent type when MISSING unions appear in both a base class and its container. Controls remove MISSING from one side or replace it with None. [1]

The handover decision

Declare the allowed response paths. Stop delivery when child-only paths appear, then review the serializer and the missing-value policy together. Retain response_path, declared_public, and emitted so the presence of valid parent fields does not conceal extra disclosure. [1, 3]

A reference defined before the output

The illustrative response permits only parent_field. A count of 0 emitted paths outside that set is normal. If child_field is emitted too, the outside-set count is 1 and the response fails. The allowed set comes from the publication contract rather than from all attributes available on the object. [1, 3]

The scoped Truthound check

Truthound Core 3.3.2 offers NotInSetValidator to check prepared output paths against forbidden paths. Finding every path outside an allowlist first requires reconciling the declared and emitted sets. The tool neither reserializes the response model nor decides the disclosure policy. [1, 2, 3]

Limits and alternative choices

Blocking a field does not certify overall privacy, and replacing MISSING with None can change omission into an explicit null. Project into an explicit response model and keep the source object separate from the serialized object. An endpoint contract that intentionally publishes child fields must include those paths in its allowed set. [1, 3]

Application conditions

Prepare the declared public-path inventory and actual emitted paths for the same response, including child-only paths.

Alternatives

Project into an explicit response model and keep the source object separate from the serialized object.

Limitations

  • Blocking a field does not certify overall privacy, and replacing MISSING with None can change omission into an explicit null.

Evidence

Event checked
Subject checked
Modified