From 6d1edff1b96a383edda6e4998b4ee3544bd32899 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Sat, 13 Jun 2026 19:59:58 -0700 Subject: [PATCH] fix(wizard): inject profile_so_far context into AI interview LLM prompt --- dev-api.py | 15 ++++++++++++++- tests/test_wizard_ai.py | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/dev-api.py b/dev-api.py index 3eb2f13..8746ef0 100644 --- a/dev-api.py +++ b/dev-api.py @@ -4581,7 +4581,20 @@ def wizard_ai_interview(request: WizardInterviewRequest): else: conversation_lines.append(f"Assistant: {content}") - prompt = "\n".join(conversation_lines) if conversation_lines else "User: (starting conversation)" + history_block = "\n".join(conversation_lines) if conversation_lines else "User: (starting conversation)" + + # Build profile summary to give LLM context about what's already known + if request.profile_so_far: + gathered = ", ".join( + f"{k}={repr(v)}" + for k, v in request.profile_so_far.items() + if v not in (None, "", [], {}) + ) + profile_context = f"\n\n[Already gathered: {gathered}]" if gathered else "" + else: + profile_context = "" + + prompt = history_block + profile_context try: from scripts.llm_router import LLMRouter diff --git a/tests/test_wizard_ai.py b/tests/test_wizard_ai.py index 5f473e7..74c4850 100644 --- a/tests/test_wizard_ai.py +++ b/tests/test_wizard_ai.py @@ -199,6 +199,33 @@ class TestWizardAIInterviewLLM: assert "I am Alex" in prompt assert "alex@test.com" in prompt + def test_profile_so_far_injected_into_prompt(self, client): + """profile_so_far fields must appear in the prompt sent to the LLM.""" + llm_reply = json.dumps({"reply": "Got it!", "extracted_fields": {}, "complete": False}) + captured_calls = [] + with patch("dev_api._get_effective_tier", return_value="paid"): + with patch("app.wizard.tiers.has_configured_llm", return_value=True): + with patch("scripts.llm_router.LLMRouter") as mock_cls: + mock_cls.return_value.complete.side_effect = ( + lambda prompt, system=None: (captured_calls.append(prompt) or llm_reply) + ) + client.post( + "/api/wizard/ai/interview", + json={ + "history": [ + {"role": "user", "content": "I am Alex"}, + ], + "profile_so_far": { + "name": "Alex Rivera", + "email": "alex@example.com", + }, + }, + ) + assert len(captured_calls) == 1 + prompt = captured_calls[0] + assert "Alex Rivera" in prompt + assert "alex@example.com" in prompt + def test_llm_error_returns_500(self, client): """If LLM raises, the endpoint returns 500.""" with patch("dev_api._get_effective_tier", return_value="paid"):