L

Working code vs Correct code

It ran, and it gave you an answer. An answer is not a right answer — and the input you tried is the one you already had in mind.

Two runs. One name broke it.

The same script, the same day. The only difference is whose name went in.

Run A

sendInvite("John Smith") — runs, sends, returns success.

Green. This is the run people mean when they say it works.
Run B

sendInvite("José García") — crashes on the encoding.

Same code, same minute. Nothing changed except an accent, and the accent was always going to arrive.
Both are the code working. One of them is the input you thought of.

What each one actually is

Working is a fact about one run. Correct is a claim about every run you have not done.

Working is a fact about one run. Correct is a claim about every run you have not done. The test you reach for first is always the case you already had in mind, which is why it passes.

And the dangerous version does not crash. Skipped rows, dropped decimals and a weekend deadline all produce output — a wrong number looks exactly like a number.

The move is not more careful reading. It is deciding, before you run anything, which inputs you actually care about — blank, huge, foreign, zero, negative, duplicated — and trying those.

Sort six inputs, then see what each breaks

Tap an input, then tap whether the code survives it. Then see exactly what each one does to it.

The same gap, different desk

Pick a situation. In every one, the tested input was the ordinary one.

In every one of these, the tested input was the ordinary one.

The rows that quietly vanished

It did not fail. It returned a smaller number, and a smaller number looks exactly like a number.

Test the distinction

Five questions. Nothing is scored.

Question 1 of 5
Multiple choice

The words this pair actually contains

Five terms, not two. Tap one.

Questions people ask

Open all 20 questions
What is the difference between working code and correct code in AI-generated scripts?

Working code is code that runs successfully in one observed case—often the example you gave the AI. Correct code is code that meets the full requirements and works across all valid inputs, not only the one you tested. The difference matters when your data or situation changes.

Why does AI sometimes give me code that only works for one file?

AI models often produce code that matches the example you provide. If your example is too narrow, the code may only work for that specific case. Without more details, the AI cannot anticipate every valid input or requirement.

How can I tell if code is correct, not only working?
  1. Test the code with several different valid inputs, not only the original example.
  2. Check the requirements or rules the code is supposed to follow.
  3. See if the code handles edge cases—unusual but valid situations.
  4. Ask a colleague to try the code with their data.
What are common signs that code is only working, not correct?
  • Fails when you change the input slightly.
  • Breaks when a colleague tries it on their data.
  • Misses important checks or rules from your policy.
  • Only passes the original test, not others.
Does AI-generated code need to be checked for correctness?

Yes. Even if the code runs, you need to check it against your requirements and test it with different inputs. AI does not know your full context unless you spell it out.

Is it enough to run code once to know it's correct?

No. A single successful run only shows the code worked for that input. Correct code needs to handle all valid cases, including those you have not tested yet.

How can I make AI-generated code more likely to be correct?
  • Give clear, detailed requirements.
  • Provide examples of different valid inputs.
  • Describe edge cases or tricky situations.
  • Ask the AI to explain how it handles errors.
What is an example of working code failing in real life?

You receive a script from an AI assistant that processes your sales report perfectly. When your colleague tries it on her report, it crashes because her file has an extra column. The code worked for you, but was not correct for all cases.

Why do people confuse working code with correct code?

On the surface, both look like they do the job. If you only see one successful run, you might assume the code is reliable. Only when you try new data or requirements do the gaps show up.

How do requirements affect whether code is correct?

Requirements describe what the code must do and what situations it must handle. If the code only works for one case, it is not meeting the requirements. Correct code covers all the rules and cases you set.

Can working code become correct code?

Yes, if you extend it to handle all valid cases and meet all requirements. Often, you start with working code and improve it until it is correct.

What risks come from using only working code?
  • Unexpected failures with new data.
  • Missed deadlines when code breaks.
  • Rework and lost time fixing errors.
  • Embarrassment if a client sees the failure.
How do I test if code is correct?
  1. List the requirements and valid inputs.
  2. Try the code with different data sets.
  3. Check if it handles errors gracefully.
  4. See if it gives the right results every time.
Does correct code always mean perfect code?

No. Correct code meets the stated requirements and handles all valid cases, but it might not be optimised for speed or style. Perfection is not the goal—reliability is.

What should I do if AI code fails with a colleague's data?
  1. Compare your data with your colleague's to spot differences.
  2. Check if the code assumes a specific format or value.
  3. Update the code to handle both cases.
  4. Test again with both data sets.
Can AI code be correct if requirements are unclear?

No. If the requirements are vague or missing, the AI can only guess what you want. Clear requirements are needed for correct code.

What is an edge case in code, and why does it matter?

An edge case is an unusual but valid situation—like a blank value or a very large number. Correct code handles these cases, while working code often misses them.

How does testing help find the difference between working and correct code?

Testing with different inputs and scenarios shows whether the code only works for one case or for all the cases you care about. It is the fastest way to spot gaps.

Is it safe to use AI code in production if it works once?

No. A single success does not guarantee reliability. Production code needs to be correct—able to handle all valid cases and meet your requirements every time.

What questions should I ask before trusting AI-generated code?
  • What requirements does this code need to meet?
  • Have I tested it with different valid inputs?
  • Does it handle errors or edge cases?
  • Would it work for my colleague's files too?

One green run tells you about one input. Correct is a claim about all of them.

Copyright © Pawan Nayar · LLOS.ai · 2026 — Working code vs Correct code: it ran once, versus it holds for every real case.Original pedagogy, voice, and design — all rights reserved.