Python for network data: collect, parse, validate, then trust
A network reply becomes a decision only after a gate decides whether it can be trusted.

A script that reads a device is not yet an automation; it becomes one when it knows when to refuse. Collecting, parsing and validating are separate jobs, and the third must be able to stop the fourth: a reply trusted only because it arrived makes every later step inherit an unknown. That pipeline, for network data, is this sheet’s subject; the generic JSON-and-schema problem belongs to the Automation & AI sheet.
Five steps that must not merge
The work separates into five steps, not a menu. Collect fetches a reply from a device: an interface status, a routing table, a counter. Normalise turns it into one shape whatever produced it. Validate asks whether that shape is one the script may act on. Act is the decision — a report, an alert, a change. Record writes down what was collected, what it validated to and what was done, so the run can be reconstructed.
The order is the point: validation is a gate, not a formatting step. If acting can happen when validation did not, the pipeline guarantees only that something was fetched.
collect ──► normalise ──► validate ──► act ──► record
raw text one shape gate: decision evidence
may we act?
Reading text against consuming a model
Two ways to get data out of a device fail differently. The first reads the CLI’s text with a regular expression: its failure mode is exact — the layout is a display convention, not a contract, and it changes with the software version, so a parser can silently stop matching. Netmiko, a “Multi-vendor library to simplify CLI connections to network devices” (netmiko-readme.md line 12), aims to “eliminate low-level regex pattern matching to the extent practical” (line 25).
The second way consumes data that already has a declared structure. NAPALM “is a Python library that implements a set of functions to interact with different router vendor devices using a unified API” (napalm-readme.md line 9). Underneath, a model-driven interface returns data modelled by YANG, “a data modeling language used to model configuration data, state data” (RFC 7950 lines 17–20); the encoding is a separate decision, and RFC 7951 “defines encoding rules for representing configuration data, state data, parameters of Remote Procedure Call (RPC) operations or actions, and notifications defined using YANG as JavaScript Object Notation (JSON) text” (RFC 7951 lines 17–20). Structure removes the format-guessing, not the need to check the values.
The gate: what validation actually checks
A schema checks the shape of model-driven data; the generic mechanics belong to the Automation & AI sheet. Network data adds the second half: shape-valid is not value-valid. Three checks belong here.
Types and units. A model can carry a type and a unit: the YANG “units” statement gives “a textual definition of the units associated with the type” (RFC 7950 lines 3629–3631). A leaf reading 90 tells you nothing until you know it is seconds, not a percentage.
Ranges and precision. JSON’s own limits are the trap: the format “allows implementations to set limits on the range and precision of numbers accepted” (RFC 8259 lines 407–408), and only integers “in the range [-(253)+1, (253)-1] are interoperable” (lines 419–420). A model-driven encoding answers this by shape — a 64-bit value is “represented as a JSON string” (RFC 7951 lines 586–589) — so a validator checks the type it received, not merely that a number arrived.
Cross-field consistency. Two fields that must agree, or one that must move one way, are where a schema is silent. A cumulative counter that has gone backwards is a restart, not a negative rate — the counter mechanics are the L3 telemetry sheets’ — and a validator that computes a rate without checking reports a spike that never happened.
Determinism: the same input, the same decision
A pipeline worth re-running depends only on its input, and that begins with ordering: a JSON “object is an unordered collection of zero or more name/value pairs” (RFC 8259 lines 162–164), so comparing two replies as text, or in the order keys happen to appear, compares something the format never promised. Compare on values, sort before you diff, and keep whatever varies per run out of what decides. Idempotency is the same rule from the other side: a re-run on unchanged input must yield the same decision, not a second one.
A device that does not answer is unknown, not well
A device that times out, refuses the connection, or returns half an answer is unknown; a default that reads unknown as healthy turns an outage into a green report. A partial result must be marked partial, not completed. Where the pipeline writes, the safe default changes nothing: the Network Configuration Protocol (NETCONF) gives that a shape — a “candidate configuration datastore: A configuration datastore that can be manipulated without impacting the device’s current configuration” (RFC 6241 lines 349–353) — and the commit is explicit: “If the device is unable to commit all of the changes in the candidate configuration datastore, then the running configuration MUST remain unchanged” (RFC 6241 lines 3036–3038). When a step fails, fail toward the state you can still describe.
Level and prerequisites
L5 — specialist and automation. It assumes the L3 telemetry sheets for counters and metrics, and the sibling sheets that use collection: device APIs and platform interfaces, Ansible, validation and rollback, drift detection.
Where to go next
References
- RFC 7950 — The YANG 1.1 Data Modeling Language (M. Björklund, Ed., August 2016, Standards Track). YANG as a data modeling language and the “units” statement.
- RFC 7951 — JSON Encoding of Data Modeled with YANG (L. Lhotka, August 2016, Standards Track). The JSON encoding rules and the string encoding of 64-bit values.
- RFC 8259 — The JavaScript Object Notation (JSON) Data Interchange Format (T. Bray, Ed., December 2017, Standards Track). The object as an unordered collection and the interoperability limits on numbers.
- RFC 6241 — Network Configuration Protocol (NETCONF) (R. Enns, Ed., June 2011, Standards Track). The candidate configuration datastore and the commit that leaves the running configuration unchanged on failure.
- NAPALM — project documentation (napalm-automation/napalm, README). The unified API across vendor devices.
- Netmiko — project documentation (ktbyers/netmiko, README). Multi-vendor CLI connections and the aim to reduce regex matching.