defensive-coding

Validate data flows across system boundaries with layered checks and structured logging.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/cyarie/cyarie-claude-plugin --skill defensive-coding
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: defensive-coding
Source: https://github.com/cyarie/cyarie-claude-plugin/tree/main/skills/defensive-coding
Command: npx skills add https://github.com/cyarie/cyarie-claude-plugin --skill defensive-coding

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Defensive coding makes bugs structurally impossible rather than temporarily fixed. The core principle: validate at every layer data passes through, and instrument for observability so failures are diagnosable. A bug isn't fixed until it's impossible.

Core Features & Use Cases

  • Layered validation across entry points, business logic, environment guards, and observability
  • Clear exception handling with context propagation
  • Structured logging and tracing for diagnosability
  • Guards against dangerous operations and unsafe contexts

Quick Start

Instrument multi-layer validation and observability in your module to prevent defects.

Frequently Asked Questions about defensive-coding

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is defensive coding and when do I need layered validation?

Defensive coding structurally prevents bugs by validating data at every layer it passes through. You need it when input comes from external sources, data crosses service boundaries, or operations may be destructive.

How do I implement input validation across system boundaries?

Implement input validation by applying guards at entry points, business logic layers, and environment boundaries. This multi-layer approach ensures data is checked continuously as it crosses service boundaries rather than once at the edge.

What's the best way to add observability and structured logging for diagnosing failures?

The best way to add observability is instrumenting structured logging and tracing with context propagation throughout your module. This ensures that when validation failures occur, they are fully diagnosable through clear exception handling.

How do I set up environment guards against dangerous operations?

Set up environment guards by validating operational context before executing potentially destructive actions. These guards prevent unsafe contexts from running dangerous operations by checking conditions structurally rather than relying on temporary fixes.

Why does defensive coding make bugs structurally impossible instead of temporarily fixed?

Defensive coding makes bugs structurally impossible because it enforces validation at every layer and instruments observability for diagnosability. A bug is not considered fixed until the code structure makes it physically impossible to recur.

Can I use defensive coding for multi-layer validation without external dependencies?

Yes, you can implement multi-layer validation, environment guards, and structured observability directly within your module. The approach requires no external dependencies to validate data flows and prevent bugs across system boundaries.