Command Palette

Search for a command to run...

Hectal
Phase 7: Query Understanding
RAG and Vector Search · Exercise 3 of 6 PreviousNext
Intermediate

Guard a model's rewrite

A model was asked to rewrite a question. Write accept_rewrite(reply, original, max_words=12) that returns the reply (with surrounding whitespace removed) only if it is not empty, has no line break inside it, and has at most max_words words. Otherwise it returns original.

What Check tests

  1. A good reply is accepted and trimmed
  2. An empty reply falls back
  3. A reply of only spaces falls back
  4. A long reply falls back
  5. A multi-line reply falls back

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.