Skip to content
Working with AI

Ask AI for code you can actually evaluate

Turn a vague coding request into a bounded task with context, constraints, examples, and a clear way to check the result.

By Hunicode Team · · 5 min read

On this page
  1. Begin with the outcome
  2. Supply the context that affects the change
  3. Include examples that reveal boundaries
  4. Specify the size of the response
  5. Evaluate the answer against the contract
  6. Refine with evidence
  7. Keep a reusable request checklist

A useful coding request gives you a way to judge the answer. The assistant needs enough context to propose a relevant change, and you need a clear contract to decide whether that change is correct. More words do not automatically make a better prompt. Specific facts, explicit limits, and checkable examples usually do more work than a long description of the assistant's supposed expertise.

This guide uses a small TypeScript task to show how to move from an ambiguous request to a reviewable result. The same structure applies to bug fixes, refactoring, and test generation.

Begin with the outcome

“Write a validator” leaves several important decisions unspecified. What input does it accept? Does failure throw an exception or return a result? Are blank strings allowed? Should valid strings be transformed?

Suppose you need a function that accepts a page value from a URL and returns a positive integer, falling back to 1 for invalid input. A more useful description is:

Implement parsePage(value: unknown): number in TypeScript.
Accept strings containing only decimal digits, without leading zeros,
and with numeric values from 1 through Number.MAX_SAFE_INTEGER.
For all other input, return 1. Do not coerce objects or arrays.

This contract makes several decisions explicit. It rejects numeric inputs even if they contain a valid number. It rejects whitespace around a number. It rejects scientific notation. Those choices are examples for this task; another application could reasonably choose different behavior. State the behavior your application needs.

Supply the context that affects the change

Include the existing signature, relevant callers, and nearby conventions. If errors elsewhere use a result object, show that pattern. If a library already solves the problem, identify it. If there are no dependencies, say so rather than letting the assistant assume it can add one.

You rarely need to paste an entire repository. Start with the smallest set of files that explains the behavior and its integration. Add more context when an unresolved question depends on it. Before sharing any code with an external tool, follow the rules that apply to that code and remove credentials or other data the task does not require.

For the page parser, useful context might be that the result feeds pagination, the application uses strict TypeScript, and the function must work in both server and browser modules. A screenshot of the page design would add little to this particular implementation decision.

Include examples that reveal boundaries

Examples are compact specifications. Include both accepted and rejected input, especially cases that common conversion functions handle differently:

InputExpected resultReason
"4"4Valid positive decimal integer
"0"1Zero is outside the range
"02"1Leading zeros are disallowed
"2.5"1Fractions are disallowed
"2cats"1The whole string must be valid
["3"]1Arrays must not be coerced
"9007199254740992"1Outside the safe integer range

Without the "2cats" example, an implementation using parseInt might appear adequate. Without the array example, generic coercion might slip through review. Examples should expose decisions that matter, rather than repeating the same ordinary case with different values.

Specify the size of the response

Ask for a patch you can inspect. For a small function, that could mean the function and focused tests, with a brief explanation of any assumptions. For a larger change, ask for a plan first and identify the files that may change.

A complete request for this example could be:

Implement parsePage(value: unknown): number using the contract and
examples above. Use no new dependencies. Keep it as a pure function.
Add table-driven tests using the project's existing test framework.
Explain any assumption not covered by the contract. Do not change
callers or unrelated pagination behavior.

Output constraints help manage review work. They do not guarantee compliance. Still inspect the resulting diff and check whether the assistant modified files outside the requested scope.

Evaluate the answer against the contract

A plausible implementation is:

export function parsePage(value: unknown): number {
  if (typeof value !== "string" || !/^[1-9]\d*$/.test(value)) {
    return 1;
  }
  const page = Number(value);
  return Number.isSafeInteger(page) ? page : 1;
}

Read it in the order the contract is enforced. The type check rejects arrays and objects before conversion. The pattern requires the entire string to be decimal digits with a nonzero first digit. The final check rejects values that cannot be represented as safe integers.

Run the examples and inspect what the tests actually assert. If the assistant wrote both implementation and tests, they can share the same misunderstanding. Derive at least some expected results independently from the contract. For a real URL path, separately decide how your framework's repeated query parameters reach this function; the parser alone cannot establish that integration behavior.

Refine with evidence

When the result is wrong, give the failing input, the expected result, and the actual result. Ask for the cause and a targeted correction. “Make it more robust” is hard to evaluate; “The parser accepts 2cats, which the contract rejects” is actionable.

If the answer repeatedly misses the target, inspect the request itself. Perhaps two requirements conflict, an important caller is missing, or you asked for too much in one change. Breaking the task into contract clarification, implementation, and review can make the uncertainty easier to locate.

Sometimes the best follow-up asks for analysis rather than more code: “Which of these cases would fail with parseInt, and why?” This helps you understand a proposed choice before accepting it.

Keep a reusable request checklist

Before submitting a coding request, check that you can answer these questions:

  • What observable behavior should change?
  • Which existing interfaces and conventions must it fit?
  • Which inputs, boundaries, and failures define correctness?
  • How large a patch am I ready to review?
  • What command or manual check will verify the result?

After receiving the answer, return to those same questions. A useful prompt starts a review process; it does not replace one. Continue with a practical review process and tests beyond the happy path to turn the generated result into a change you understand.

Try it in a real coding round.

A little practice makes these ideas your own.

Find a practice challenge →
← Back to guides