Level 2Unit D · Session 23
23

Unit D · AI and chatbots

Prompting well, and debugging with it

What we are making: the difference between a useless answer and a useful one — and a genuinely good use for a chatbot in this subject.

The idea

A chatbot gives you an answer shaped like your question. Vague in, vague out. People then blame the chatbot.

YOUMy robot code does not work.✗THE CHATBOTThere are many reasons robot code might not work. Check yourwiring, verify your power supply, make sure your pins areconfigured correctly...YOUArduino Uno, C++. My line follower turns the wrong way atcorners. Sensor on A0 reads 180 on black tape and 850 on thepale floor. My threshold is 500. Here is my loop: [code]. Whatis most likely wrong?✓THE CHATBOTYour logic treats a HIGH reading as 'on the line', but yournumbers say the opposite — black tape gives the LOW value. Tryswapping the comparison to reading < threshold, or swappingwhich motor you slow.
Same chatbot, a minute apart. The difference is entirely in the question.

The five things to include

  • The setup. Board, language, what the thing is meant to do.
  • The actual numbers. Your sensor readings, your threshold. Not 'a value'.
  • The code, or the part of it that matters.
  • What you expected, and what happened instead. Both.
  • What you have already tried. Stops it suggesting the thing you did ten minutes ago.
💡 Tip
That list is not really about chatbots. It is exactly what you should say when you ask a person for help too, and it is why teams who write good prompts also get better help from their teacher.

Do it — debug with it, properly

Your teacher gives each team a broken program. It compiles. It behaves wrongly.

  1. First, work on it yourselves for ten minutes. No chatbot. Write down what you think is wrong.
  2. Now write a prompt with all five things from the list. Take your time over it.
  3. Read the answer. Do not paste it in.
  4. Decide whether you agree, and say why, in your notebook.
  5. Make the change yourself, by typing it. Test it.
⚠ Careful
The ten minutes first is not a punishment. A chatbot answer lands much better when you already understand the problem, and you will spot a wrong suggestion — which you will get — instead of pasting it in and being confused for half an hour.

When it is wrong about code

It will be, fairly often, and in a particular way: the suggestion looks completely reasonable and does not work. Watch for these.

What you seeWhyWhat to do
It invents a function that does not existIt has seen similar libraries and blended them.If the compiler says 'not declared', the function may simply not be real.
It uses a library you do not haveIt assumed a setup you did not describe.Say which libraries you actually have installed.
It rewrites your whole programYou did not tell it to change only one thing.Ask for the smallest change that fixes it.
It agrees with whatever you suggestAgreement is a very likely next word.Ask 'what is wrong with that approach?' and see if it changes its mind.
⚠ Careful
That last row is worth testing today. Tell it confidently that something wrong is right, and see whether it agrees with you. Many will. A tool that agrees with you is not checking your work.

The honesty rule

There is a line, and it is worth being completely clear about where it sits.

FineAsking it to explain an errorAsking why your code misbehavesAsking what a function doesAsking for three approachesAsking it to check your spellingNot fineAsking it to write the programPasting its code in unreadHanding in what you cannot explainUsing it during a testUsing it and not saying so
The test: could you explain every line you hand in, to somebody who asks? If not, it is not yours.
⚠ Careful
Your teacher can nearly always tell, and not because of clever detection software. It is because the code suddenly uses things you have never been taught, and because you cannot answer a question about your own work.

Say when you used it

From now on, in your notebook, one line whenever a chatbot helped: what you asked, and what you did with the answer. That is not a punishment either. It is what engineers do with any source, and it makes the help you got part of the record rather than a secret.

What you learned

  • A vague question gets a vague answer.
  • Include setup, real numbers, the code, expected vs actual, and what you tried.
  • Work on it yourself first. Then ask.
  • Read the answer and decide. Do not paste.
  • It will agree with you even when you are wrong.
  • Write down what you asked and what you did with it.
Challenge optional — only if you finish early
  • Give a chatbot a real error message from your own code and judge whether its fix is right.
22. What a chatbot is