← Questions

Validate a parsed config against field descriptors

0
Applied IntuitionCodingLast asked Apr 2026

A coding interview question asked in Applied Intuition's AI-assisted build round, last asked Apr 2026. It tests validation, recursion and schemas.

A configuration file has already been parsed from YAML or JSON into nested dicts, lists and primitive values. A set of descriptors says what a valid config looks like: for each message type, its fields, each field's type (a primitive or another message type), and whether it is required or repeated. Write a validator that returns every problem in the config, each with the path to the bad field and the reason. Agree on the descriptor format with the interviewer before you code.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • Field(type, required=True, repeated=False), where type is one of "string", "int", "float", "bool" or a message descriptor.
  • A message descriptor is a dict from field name to Field.
  • validate(config: dict, descriptor: dict) -> list[str]: one error per problem, as "<path>: <reason>". Paths use dots for fields and [i] for list items. An empty list means the config is valid.

Rules: a required field must be present; a field not in the descriptor is unexpected; a repeated field must be a list whose every item matches the type; bool is not an int, and an int is accepted where a float is expected. Report errors in descriptor field order, then unexpected fields in config order.

Example

ADDRESS = {"street": Field("string"), "city": Field("string"),
           "zip": Field("string", required=False)}
PERSON  = {"name": Field("string"), "age": Field("int"),
           "address": Field(ADDRESS), "tags": Field("string", repeated=True)}

validate({"name": "Ada", "age": "36", "address": {"street": "1 Main"},
          "tags": ["x", 3], "nick": "a"}, PERSON)
->  ["age: expected int, got string",
     "address.city: missing required field",
     "tags[1]: expected string, got int",
     "nick: unexpected field"]

validate({"name": "Ada", "age": 36, "address": "1 Main", "tags": []}, PERSON)
->  ["address: expected object, got string"]

Constraints

  • Configs nest to any depth; collect all errors rather than stopping at the first.
  • No schema-validation library.

Clarifying questions

  • What do the descriptors look like, and can a descriptor refer to itself (a tree of nodes)?
  • Is null allowed for an optional field, and is an empty list valid for a required repeated field?
  • Should numbers be coerced (the string "36", the float 36.0 for an int), or rejected?
  • Are unexpected fields errors, warnings or ignored?
  • What error format do callers need: strings, or structured objects with path, expected and actual?

What a strong answer covers

  • A recursive walk that carries the current path and appends errors, with separate handling of primitives, nested messages and repeated fields.
  • Exact type checks for JSON values, including the bool versus int trap in Python.
  • Missing, unexpected, wrong-type and bad-list-item errors, all reported in one pass with precise paths.
  • O(size of the config) time; recursion depth bounded by nesting, or an explicit stack.
  • Tests for each error kind, deep nesting, empty lists and a fully valid config.

Follow-ups

  • Add defaults, enums and numeric ranges to the descriptors.
  • Support oneof: exactly one of a set of fields must be present.
  • Load the descriptors themselves from a file, and validate the descriptors first.

Where it's asked

  • Applied Intuition · AI-assisted build · Last asked Apr 2026120 min · Build the designed system, or a small web app, in a prepared environment over two to three hours · Claude Code or a provided Claude model expected

What it tests

validation · recursion · schemas

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding