1. Learn
  2. /
  3. Courses
  4. /
  5. AI Agents with Hugging Face smolagents

Connected

Exercise

Say More, Agent: Enforcing Answers Length

You're building a real estate assistant that helps users find homes based on their preferences. Sometimes, the agent gives overly brief or vague recommendations, like "You should check out this house in Brooklyn."

To make responses more helpful, you want to validate that each answer contains at least 200 characters. If it's too short, the agent should try again using your error message as guidance.

In this exercise, you'll write a validation function that checks the length of a response.

Instructions

100 XP
  • Check if the final_answer is shorter than 200 characters. If it is, raise an exception with a helpful error message.
  • If it passes the check, return True to mark the answer as valid.