def generate_search_query(scenario, persona, listing_db): """Generate a realistic user query about listings""" # Pull real listing data to ground the generation sample_listings = listing_db.get_sample_listings( price_range=persona.price_range, location=persona.preferred_areas ) # Verify we have listings that will trigger our scenario if scenario == "multiple_matches" and len(sample_listings) < 2: raise ValueError("Need multiple listings for this scenario") if scenario == "no_matches" and len(sample_listings) > 0: raise ValueError("Found matches when testing no-match scenario") prompt = f""" You are an expert real estate agent who is searching for listings. You are given a customer type and a scenario. Your job is to generate a natural language query you would use to search these listings. Context: - Customer type: {persona.description} - Scenario: {scenario} Use these actual listings as reference: {format_listings(sample_listings)} The query should reflect the customer type and the scenario. Example query: Find homes in the 75019 zip code, 3 bedrooms, 2 bathrooms, price range $750k - $1M for an investor. """ return generate_with_llm(prompt)