When AI-generated code keeps failing, do not rush to rephrase the question. Most errors do not mean the AI cannot code; they mean it is missing key information: the library versions, the runtime environment, and the full error message. Fill in those three things and the same code often runs the first time.
Step one: paste the complete error back unchanged
Pasting only the last line of an error is usually not enough. Paste the full error from the first line to the last, together with the command that was run, the file name and the line number, and add: this is the complete error; please locate the cause first and then give the corrected full code. Often the AI first fills in code by guessing, and only after seeing the complete error can it find that the real problem is elsewhere: a missing dependency, a wrong path, or a changed API in a new version. Do not rely on screenshots of errors; a text version is easier for the AI to check line by line.
Step two: state the versions and environment
The same code behaves very differently across versions. Tell the AI your language version, framework and key library versions, operating system, and whether the code runs locally, on a server or in an online environment. If the error relates to a library version, ask directly whether that syntax still works in that version and whether there is a replacement. If you do not know the versions, run the version-check command first and paste the result; do not report an approximate version from memory.
Step three: narrow the scope and try again
If a whole block of code fails, split it up: keep only the dozen or so lines that reproduce the problem, run them alone, confirm the problem is still there, and paste that minimal code to the AI. Change one thing at a time, run it immediately, confirm whether the error changed, and then continue. Do not apply three changes from the AI at once; if something breaks, you will not know which change caused it. When account keys, database passwords or company intranet addresses are involved, replace sensitive information with placeholders before pasting, and do the same inside error messages.
If it still fails, ask differently
If the same problem has been asked twice without a fix, change the question: ask the AI to explain what each line of the error means, then to give the smallest fix that changes only one place. You can also ask it to add print output so you can see how far the program actually gets and what the variables really hold. An error message is not a failure; it is the most direct clue for locating the problem, and understanding it saves more time than asking again.