AI-Assisted Programming: The Cost of Skipping Checks and How to Build a Verification System

    This article explains why AI-generated code often breaks during repeated updates, how vibe coding differs from production delivery, and which defect types to look for. It then describes a five-layer verification approach covering static checks, unit tests, integration and contract tests, human review, and production monitoring. It also covers how to manage model version drift and set up team review workflows.

    1. Symptoms: Why Every Update Brings New Problems

    Many developers run AI-generated code, see the page work, and commit it without further checks. This approach can be acceptable during prototyping. Once a project enters continuous iteration, however, the problems surface quickly. Three typical symptoms appear.

    First, the same requirement produces different results across generations. Large language model outputs are stochastic. Even with a low temperature setting, code structure, error handling, and boundary checks can differ across sessions and context lengths. A branch fixed today may be overwritten when the code is regenerated tomorrow.

    Second, model upgrades cause behavior drift. Model iterations usually change training data, alignment strategies, and inference behavior. For users, the prompt stays the same, but the output changes. A feature that ran correctly before an upgrade may show deviations in exception handling or data formats afterward.

    Third, fixing one defect introduces another. AI is good at local patches but does not always understand global constraints. Fixing a null-value issue may remove existing logging or change an interface’s return structure, which then breaks the callers.

    The common root cause of these three problems is that generated output lacks a verifiable contract. Without tests, specifications, or review, code correctness depends on luck.

    2. The Limits of Vibe Coding: Fast Generation Is Not Reliable Delivery

    “Vibe coding” refers to a development style in which developers describe requirements based on intuition, let a tool generate code, and then judge whether the code is usable by running it. This style lowers the cost of writing boilerplate and suits exploratory prototypes and one-off scripts.

    The problem is that prototype code and production code have different requirements. Production code must handle abnormal inputs, concurrent access, resource release, permission checks, and long-term maintenance. Applying prototype acceptance criteria to production assumes that a person has read and tested every code path. That assumption often does not hold for AI-generated code.

    Responsibility also needs to be clear. Whether code is written by hand or generated by a tool, the person who submits it is responsible for its behavior. The tool only executes the task, and the team defines the acceptance criteria. Teams should require that for any code merged into the main branch, the submitter can explain what the code does, why it does so, and which inputs would cause it to fail.

    3. Common Defect Types and How to Identify Them

    Understanding defect types helps in designing targeted checks. The following categories appear frequently in generated code.

    1. Missing boundary conditions. Empty strings, zero values, negative numbers, very long inputs, and extreme numeric values are often overlooked. Generated code usually assumes that input data is ideal.

    2. Missing or overly broad error handling. Some implementations raise low-level exceptions directly, exposing internal details. Others use empty exception branches that hide errors, so failures go undetected.

    3. Fabricated interfaces or parameters. A model may call functions that do not exist or mix parameter names from different versions. These issues usually surface during compilation or at runtime. In dynamic languages, however, they may only trigger on a specific code path.

    4. Security vulnerabilities. These include unvalidated user input, database queries built by string concatenation, hard-coded keys, and overly broad file access permissions.

    5. Resource and concurrency issues. Unclosed connections, incorrect lock ordering, and unprotected shared state often appear only under load.

    Here is an example. The requirement is to parse a user-entered amount string. The first generated implementation looks like this:

    1. def parse_amount(text):
    2. return float(text.replace(",", ""))

    This code has three problems. An empty string raises an unhandled exception. Using floating-point numbers to represent money introduces binary precision errors. Negative numbers and non-finite values, such as infinity or NaN, are not rejected.

    The corrected version uses a fixed-point decimal type and defines the input and output contract explicitly:

    1. from decimal import Decimal, InvalidOperation
    2. def parse_amount(text: str) -> Decimal:
    3. if not isinstance(text, str):
    4. raise TypeError("Amount must be a string")
    5. cleaned = text.strip().replace(",", "")
    6. if not cleaned:
    7. raise ValueError("Amount must not be empty")
    8. try:
    9. value = Decimal(cleaned)
    10. except InvalidOperation as exc:
    11. raise ValueError(f"Cannot parse amount: {text!r}") from exc
    12. if not value.is_finite():
    13. raise ValueError("Amount must be a finite number")
    14. if value < 0:
    15. raise ValueError("Amount must not be negative")
    16. return value.quantize(Decimal("0.01"))

    The value of this fix lies not in the line count but in turning implicit assumptions into explicit rules. Each rule can be covered by a test.

    4. A Layered Verification System

    Running code once to confirm it works covers too little. Verification should be organized in layers, with each layer catching different types of problems.

    Layer 1: Static checks. These include type checking, code style checks, and static security scanning. This layer costs the least. It can run automatically before submission and catch type mismatches, unused variables, and obvious injection risks.

    Layer 2: Unit tests. Write test cases for the normal and error paths of each function. For the amount parser above, the tests should cover the following:

    1. import pytest_like_placeholder

    The line above is only a placeholder. In a real project, use the parameterized testing features of the team’s test framework and list inputs and expected outputs in a table:

    1. cases_ok = [
    2. ("1,234.5", "1234.50"),
    3. (" 0 ", "0.00"),
    4. ]
    5. cases_error = ["", "abc", "-1", "NaN"]
    6. for raw, expected in cases_ok:
    7. assert str(parse_amount(raw)) == expected
    8. for raw in cases_error:
    9. try:
    10. parse_amount(raw)
    11. raise AssertionError(f"Expected rejection of input: {raw!r}")
    12. except (ValueError, TypeError):
    13. pass

    Formal tests should run in the test framework. The loop above only shows how to organize tests. Valid inputs must produce the correct result, and invalid inputs must be rejected.

    Layer 3: Integration and contract tests. Generated modules often interact with databases, message queues, and external services. Integration tests verify behavior after modules are combined. Contract tests verify that the caller and the callee share the same understanding of the interface format. After a model upgrade or code regeneration, contract tests can be the earliest way to detect interface changes.

    Layer 4: Human review. Automation cannot judge whether the intent is correct. For example, it cannot decide whether a discount should be applied first or last. Reviewers should focus on the diff, confirm that the generated code did not change unrelated logic, and check that existing validation or logging was not removed.

    Layer 5: Production observation. Logs, metrics, and alerts reveal scenarios that tests do not cover. Error rates, latency, and the distribution of exception types in production are the final evidence of whether generated code is stable.

    5. Managing Version Drift

    Version drift cannot be fully avoided, but its impact can be limited.

    1. Pin dependency versions. Third-party libraries, runtimes, and build tools should all have fixed version numbers. Unexpected dependency upgrades can conflict with the assumptions behind generated code.

    2. Record the generation context. For critical modules, save the requirement description, prompt template, model version, and output. When a problem occurs, the team can reproduce the generation process and determine whether a change in input or in the model caused it.

    3. Build a golden test set. Organize typical inputs and expected outputs into data files, and replay them automatically after each model or dependency upgrade. If the output deviates from expectations, block the merge and notify the owner.

    4. Compare critical paths with diffs. After an upgrade, regenerate the code for the same requirement and compare the old and new versions with a diff tool. Large differences need manual confirmation before they replace existing code.

    6. Team Workflow

    Individual habits are hard to sustain, so the process should be written into team standards.

    First, generated code must come with tests. Code without tests does not enter review.

    Second, commit messages should state which parts of the change were AI-assisted. This helps reviewers focus on the generated sections and makes it easier to trace the source of later issues.

    Third, reviewers must be able to explain the code line by line. If a reviewer cannot explain what a section of logic does, the submitter should rewrite or remove it. “The model generated it, so it should be fine” is not a valid reason to pass a review.

    Fourth, set measurable metrics. Track the number of defects per merge, rollback counts, and the sources of production incidents. The purpose of these metrics is not to assign blame. They help teams decide which kinds of requirements suit tool generation and which should be led by people.

    7. Summary

    AI-generated code speeds up writing but does not reduce the amount of verification work. Defect patterns change as tools and models change, so teams need stable checking mechanisms. Static checks catch basic errors, tests fix expected behavior, contract tests guard interface boundaries, human review confirms intent, and production observation provides a safety net. Connecting these stages turns generated code from “looks like it works” into code that can be delivered continuously.