Part II: Discovery Through Software Engineering and Vibe Coding
Chapter 9: Vibe Coding As Specification, Steering, Verification, And Repair

Vibe Coding As Specification, Steering, Verification, And Repair

"I told the model what I wanted in plain English. It wrote the code. I ran the tests. The tests failed. So I told the model again, this time with feeling."

A Vibe Coder Who Read the Specification

Overview

Vibe coding is the practice of building software through conversation with an AI code generator: you describe what you want in natural language, the model generates code, you observe the result, and you steer the model toward correctness through further prompts, test results, and error messages. This chapter treats vibe coding not as a casual shortcut but as a disciplined engineering methodology with a formal loop: specify, generate, observe, steer/verify, commit or repair.

The central insight is that a natural-language prompt is a partial specification, and the gap between what you said and what you meant is the primary source of bugs in AI-generated code. We close that gap with executable contracts (test suites, type annotations, property-based checks) that make implicit requirements explicit. The result is a workflow where the human supplies intent and judgment while the AI supplies implementation velocity.

This chapter builds directly on the AI-assisted engineering foundations of Chapter 8 and sets the stage for Chapter 10: Prompting to Programming, which extends these ideas to more complex prompt engineering strategies. The verification techniques here resurface in Chapter 18: AI-Assisted Testing and QA, and the specification patterns feed into Chapter 13: Discovery of Requirements.

Prerequisites

Readers should have completed Chapter 7: Software Development as a Discovery Process and Chapter 8: Foundations of AI-Assisted Software Engineering. Familiarity with Python, pytest, and basic command-line usage is assumed. The search framework from Chapter 1 provides useful context for understanding the specification gap as a search problem.

Learning Outcomes

Sections

9.1 Natural Language as Specification

Prompts as partial specifications. The specification gap. Ambiguity, underspecification, and implicit assumptions. Measuring specification completeness. Executable contracts as gap-closers.

9.2 The Vibe Coding Loop

The five-phase loop: specify, generate, observe, steer, commit. Convergence dynamics. Session management. When to reset versus repair. Prompt refinement strategies.

9.3 Verification and Repair

Test suites as executable contracts. Property-based testing with Hypothesis. Schema validation with Pydantic. Static analysis integration. The repair loop: feeding errors back to the model.

9.4 Building Through Conversation

Recipe: building a scientific data explorer web application from scratch through iterative conversation. Failing tests first, then generation, then verification, then deployment.

What's Next

With the vibe coding loop established as a disciplined engineering practice, Chapter 10: Prompting to Programming deepens the specification side of the loop. You will learn advanced prompt engineering strategies that transform vague intent into precise, structured prompts that minimize the specification gap. Where this chapter asked "how do we close the gap between what we say and what we mean?", Chapter 10 asks "how do we say what we mean more precisely in the first place?" Together, the two chapters form a complete methodology for building software through human-AI collaboration.

Bibliography

Foundational References

Karpathy, A. (2025). Vibe coding. Coined in a social media post describing a new mode of AI-assisted programming.

The origin of the term "vibe coding," describing a workflow where programmers describe intent in natural language and let AI generate the implementation.

Jiang, S., et al. (2024). Self-planning code generation with large language models. Proc. ICSE 2024.

Demonstrates that LLMs can decompose complex coding tasks into plans, then generate code step-by-step, improving correctness on benchmarks.

Chen, M., et al. (2021). Evaluating large language models trained on code. arXiv:2107.03374.

The Codex paper introducing HumanEval, establishing pass@k as the standard metric for code generation quality.

Verification and Testing

MacIver, D. R. (2024). Hypothesis: Property-based testing for Python.

The leading property-based testing library for Python. Generates test inputs automatically to find edge cases that hand-written tests miss.

Colvin, S. (2024). Pydantic: Data validation using Python type annotations.

Runtime data validation through type annotations, providing executable schema contracts for function inputs and outputs.

Microsoft (2024). Playwright for Python.

Cross-browser end-to-end testing framework for web applications, used in Section 9.4 for verifying the Discovery Workbench UI.

Tools and Platforms

Anthropic (2025). Claude Code: An agentic coding tool.

The primary vibe coding tool used throughout this chapter, operating as an agentic command-line assistant that reads, writes, and tests code.

pytest development team (2024). pytest: helps you write better programs.

The standard Python testing framework used throughout this book for executable contracts and verification.

Lehtosalo, J., et al. (2024). mypy: Optional static typing for Python.

Static type checker that catches type errors before runtime, complementing the dynamic verification approach of testing.

Research

Olausson, T. X., et al. (2023). Is self-repair a silver bullet for code generation? arXiv:2303.17491.

Empirical study of LLM self-repair capabilities, showing that feeding error messages back to the model improves pass rates but with diminishing returns.

Ridnik, T., et al. (2024). Code generation with AlphaCodium: From prompt engineering to flow engineering. arXiv:2406.12952.

Introduces flow engineering for code generation, demonstrating that structured generate-test-repair loops outperform single-shot generation.

Zhong, L., & Wang, Z. (2024). LDB: A large language model debugger via verifying runtime execution step by step. arXiv:2402.01030.

Shows how step-by-step runtime verification can guide LLM debugging, achieving significant improvements on code generation benchmarks.