← Back to catalogue
Published

defensive programming

vr.tr.defensive-programming · thing-q1182643

Enable an AI agent to recognise defensive programming practices, assess whether they protect stated assumptions and invariants, and select proportionate responses to unexpected conditions.

Thing Registry Information and virtual systems INF.KNW

Bundle → Layer → Finding → Questions Filled

6 bundles · 11 layers · 16 findings · 26 questions

Assumptions and contracts The expectations a program relies on and the guarantees it must preserve when those expectations fail.

Caller obligations

Preconditions at interfaces and responsibility for checking them.

Explicit preconditions

Record accepted inputs, required execution context and the party responsible for enforcing each precondition.

  1. Which values, object states or calling sequences violate this interface's preconditions? definition
  2. Which preconditions must the callee check, and which may it rely on callers or construction rules to guarantee? boundary

State invariants

Conditions that must hold before, during or after operations.

Invariant enforcement

Record invariants, permitted temporary violations and whether enforcement prevents or detects invalid states.

  1. Which invariants must remain true at observable points, including exceptional exits? definition
  2. Can restricted types or validated constructors prevent the invalid state, or is an execution-time check required? action
Boundary validation How data becomes acceptable for use after crossing an interface or trust boundary.

Acceptance rules

Structural and semantic conditions for accepting incoming data.

Input acceptance

Record checks for representation, ranges, sizes and relationships among values before consequential use.

  1. Which checks establish structural validity, and which establish validity for this operation's meaning? definition
  2. At what point are malformed, oversized or inconsistent inputs rejected before allocation, indexing or state mutation? action

Validation lifetime

The conditions under which an earlier validation remains applicable.

Validated value continuity

Record whether transformation, mutation or concurrent access can invalidate a check before the value is used.

  1. Can decoding, normalisation, shared mutation or elapsed time change the checked value or its relevant context? boundary
  2. Should use be coupled atomically to the check, operate on an immutable snapshot or require revalidation? action
Failure and state integrity How detected violations become explicit outcomes while preserving valid program state.

Failure signalling

How unexpected conditions are classified and communicated.

Guard and assertion policy

Record distinctions among rejected inputs, operational failures and programmer defects, including the deployment behaviour of their checks.

  1. Does this condition represent invalid caller input, an expected operational failure or a broken internal assumption? definition
  2. If assertions are disabled, which required checks still execute and how are their failures reported? boundary

Exceptional exit integrity

State and resource guarantees when an operation cannot complete.

Partial operation containment

Record commit points, cleanup responsibilities and guarantees about partially completed operations.

  1. Which mutations or external effects may already have occurred when each failure path is taken? boundary
  2. How are owned resources released and valid state restored or explicitly marked as degraded? action
Dependencies and bounded recovery Defenses against dependency misbehaviour, unavailable resources and recovery attempts that could amplify failure.

Dependency assumptions

Expectations about responses, completion and resource use at dependency interfaces.

Dependency result checks

Record handling of missing, malformed, partial, late or otherwise unusable dependency results.

  1. Which dependency outcomes violate the caller's assumptions even when the dependency reports success? definition
  2. What deadlines, cancellation handling and size limits bound the caller's exposure to this dependency? action

Recovery constraints

Conditions under which retrying or falling back preserves correctness.

Retry and fallback validity

Record retry eligibility, stopping rules and the semantics of any substitute result.

  1. Can a retry duplicate an effect when the previous attempt's outcome is unknown? boundary
  2. What bounds recovery attempts, and what contract makes a fallback result acceptable and distinguishable from normal success? action
Defense evidence and proportionality Evidence of defensive effectiveness and the costs of maintaining and executing checks.

Violation path evidence

Verification and observations tied to specific failed assumptions.

Defensive outcome verification

Record evidence that a triggered defense produces the intended outcome and preserves required invariants.

  1. Which tests or fault-injection results exercise rejection, cleanup and recovery exhaustion in the deployed configuration? provenance
  2. Which observable signals confirm that the defense fired without exposing sensitive input or overwhelming diagnostics? measurement

Defense maintenance

Review of defense cost, duplication and continued relevance as contracts change.

Proportionate check placement

Record the justification for check placement and evidence needed before consolidating or removing checks.

  1. What execution overhead and maintenance burden does this defense introduce under representative use? measurement
  2. Which verified upstream guarantees would justify removing a repeated check, and could another entry path bypass them? action
Evidence and external alignment What the world already says about this thing, gathered so the model can be checked against it.

Reported evidence

Findings from the breadth pass, kept separate from the structural claims.

Check these first

Recalled without web access and unsourced; every item is a lead to verify.

  1. Which of these check these first hold for the sense of defensive programming this model covers, and on what evidence? provenance

Kinds and varieties

Recalled without web access and unsourced; every item is a lead to verify.

  1. Which of these kinds and varieties hold for the sense of defensive programming this model covers, and on what evidence? provenance

Standards and regulation

Recalled without web access and unsourced; every item is a lead to verify.

  1. Which of these standards and regulation hold for the sense of defensive programming this model covers, and on what evidence? provenance

Real-world use

Recalled without web access and unsourced; every item is a lead to verify.

  1. Which of these real-world use hold for the sense of defensive programming this model covers, and on what evidence? provenance

Failure modes and hazards

Recalled without web access and unsourced; every item is a lead to verify.

  1. Which of these failure modes and hazards hold for the sense of defensive programming this model covers, and on what evidence? provenance

Neighbouring kinds and how to tell them apart

Recalled without web access and unsourced; every item is a lead to verify.

  1. Which of these neighbouring kinds and how to tell them apart hold for the sense of defensive programming this model covers, and on what evidence? provenance

Classifiers Filled

Family
Thing Registry
Category
Information and virtual systems
Entry kind
thing
Plane
INF
Domain
INF.KNW

What it is Filled

Defensive programming is a software development approach that explicitly anticipates invalid inputs, violated assumptions and component failures and implements checks and controlled responses to preserve correctness or limit harm.

In scope

  • Assumptions, contracts and invariants that require defensive treatment
  • Validation of inputs and dependency outputs at identified boundaries
  • Defensive handling of invalid states, unavailable resources and unexpected failures
  • Containment, recovery and diagnostic behaviour of defensive controls
  • Evidence that defenses work and remain proportionate to their costs

Out of scope

  • Software engineering as the encompassing discipline
  • Complete cybersecurity threat models and security governance
  • Testing methods independent of the defensive behaviours they evaluate
  • Programming language specifications and general type-system design
  • System-wide fault-tolerance architectures beyond the code-level defenses they require

Why it exists Filled

Enable an AI agent to recognise defensive programming practices, assess whether they protect stated assumptions and invariants, and select proportionate responses to unexpected conditions.

Distinguishing features Filled

  • A defensive practice identifies an assumption that can fail and specifies the resulting behaviour; adding checks without an identified assumption is insufficient.
  • Unlike testing alone, a defense constrains construction or execution of the software when an unexpected condition occurs.
  • Unlike ordinary feature logic, a defense addresses violations of expected conditions or prevents invalid states from being represented.
  • Defensive programming addresses accidental misuse and operational failures as well as potentially hostile inputs; security-specific protection is an overlapping concern.
  • A defensive response must preserve an explicit correctness or safety requirement; silently substituting a value or catching every exception does not by itself qualify.

What robots and AI may and may not do Filled

Must not

  • Swallow errors silently so that failures go unnoticed.
  • Present code as robust or secure when its checks are missing or untested.
  • Disable safety checks in production to save effort or time.

Only with a human decision

  • Changing error-handling behaviour in safety-critical or financial systems.

May

  • Apply input validation, assertions and error handling in code it is authorized to write.
  • Review code for unchecked inputs and unsafe assumptions and report them.

Moral aspects Filled

  • Unchecked failures in software can harm people who rely on it, from patients to account holders.

Who is affected

  • Users of the software
  • Developers
  • People affected by system failures

Owners Filled

Steward

Nobody owns it; it is a software development practice.

Links to other meta-models Filled

parent

  • Q2734875 - registry parent class
  • Q39487140 - registry parent class

What else AI and robots need to interact with it Filled

Identity and identifiers required Filled

  • Vercy registry: vr.tr.defensive-programming
  • Wikidata: Q1182643 (https://www.wikidata.org/wiki/Q1182643)

Direct properties not applicable Not applicable

  • Assumption being defended: input validity | caller contract | internal invariant | dependency behaviour | resource availability | execution ordering
  • Boundary location: relationship to an external input, public interface, internal module boundary or dependency interface
  • Enforcement mechanism: type restriction | validated construction | runtime guard | assertion | structured failure handling
  • Violation response: reject | propagate failure | terminate operation | roll back | retry within limits | use specified fallback
  • Deployment activation: always enforced | configuration-dependent | development-only | disabled | unknown
  • Residual state after failure: unchanged | restored | valid but degraded | partially modified | invalid | unknown
  • Defense overhead: latency in milliseconds, memory in bytes, or operation count under a specified workload
  • Verification evidence: links to review records, static analysis, tests, fault-injection results or operational observations

Plane INF: no invented physical properties.

Recognition not applicable Not applicable

Not applicable

Defensive programming is a development approach that must be assessed through behavior and reasoning rather than visual appearance.

Capabilities and actions required Filled

  • Identify implicit assumptions and propose enforceable contracts or invariants.
  • Locate missing, duplicated or misplaced checks at software boundaries.
  • Choose a violation response consistent with state integrity and caller expectations.
  • Generate targeted cases that exercise invalid inputs, dependency failures and recovery limits.
  • Review whether assertions, fallbacks and exception handlers remain effective in deployment.
  • Recommend simplifying a defense when another verified guarantee makes it redundant.

Hazards and failure modes required Filled

  • Excessive checks can hide real errors behind default values.
  • Missing checks let invalid input corrupt data or open security holes.

Standards and interfaces required Filled

  • SEI CERT C Coding Standard, Software Engineering Institute, Carnegie Mellon University.

Context of use required Filled

  • Defensive programming is used when software must respond predictably to invalid inputs, unexpected states or failures in other components.
  • It is encountered in input validation, interface boundaries and error handling, where checks and controlled responses protect explicitly stated assumptions.

Sources Filled

  1. Wikidata item Q1182643: defensive programming - identity and sense of the item
  2. Wikipedia: Defensive programming - general description of the item

Open questions

  • Which authoritative sources should anchor this registry entry's definition and its boundary with design by contract, secure coding and fault-tolerant programming?
  • Should the registry classify defensive programming primarily as a practice, a technique family or a field of knowledge, and which classification convention supports that choice?
  • How broadly should compile-time prevention through types and validated construction count as defensive programming rather than general correctness-oriented design?
  • Which language- and runtime-specific profiles are needed to represent assertion activation, exception guarantees and resource cleanup accurately?
  • What evidence threshold should justify relying on upstream validation or removing a defense in systems with different consequences of failure?

Machine files

Provenance

thing registry research (pass 2) · unreviewed

Built from: models/things/publications/thing-q1182643/spec.json