AI CHOREOGRAPHY / THE AI / LEVEL 2 OF 5

Never trust
the answer.

The prompt asks politely for eight poses within reach, but an AI does not always obey. It may return six poses, a hand two metres away, three squats in a row, or a title full of symbols. So before anything reaches the coach, validateCoachReply checks the reply: wrong structure is rejected, numbers out of range are pulled back in. This page runs it on any reply you write.

parsetext → object (askAIJson); not JSON = failure
→
structureexactly N poses, each hand three finite numbers, or reject
→
boundsclamp every number into the reachable box
→
tidyat most one squat; a short A–Z title

An AI reply

edit it, or pick a case

validateCoachReply

What the AI asked for

What the coach will dance

The real code

coachAI.js

Two kinds of problem, two reactions. A broken structure throws an error: the scene catches it and keeps the previous routine (level 3). A value that is merely too big is clamped with limit, because the rest of the answer is still useful. The ranges are the same as in the prompt.


      
Full file: coachAI.js ↗

What you should be able to explain

  1. Reject or repair. Missing poses or a hand that is not three numbers cannot be fixed safely, so the whole reply is rejected. A number out of range can be fixed by clamping it, so it is.
  2. Safety is the game's job. The prompt asks for comfortable moves; the validator guarantees them. A player in a headset cannot see the room, so a pose must never send a hand far behind or overhead.
  3. Only known fields survive. The cleaned pose is rebuilt from a, b, squat and sway. Anything else the AI adds is dropped, so nothing unexpected reaches the shared state.
  4. The title is cleaned too. It is drawn with the scene's line font, which has only plain letters and digits, and it is shown on both headsets.

Exercises: ① Pick "a hand out of reach": which numbers changed, and to what? ② Change one pose's a to [0.2, 0.3]. Why is that rejected instead of repaired? ③ Pick "three squats": which squats are kept?