From df049375cd3f5c0541b282d2077c638f1ca2e31b Mon Sep 17 00:00:00 2001 From: fei <204683769+feiiiiii5@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:04:05 +0800 Subject: [PATCH] fix(prompts): honor empty fallback prompts --- langfuse/_client/client.py | 2 +- tests/unit/test_prompt.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/langfuse/_client/client.py b/langfuse/_client/client.py index e926e4571..6320f0a67 100644 --- a/langfuse/_client/client.py +++ b/langfuse/_client/client.py @@ -3863,7 +3863,7 @@ def get_prompt( fetch_timeout_seconds=fetch_timeout_seconds, ) except Exception as e: - if fallback: + if fallback is not None: langfuse_logger.warning( "Returning fallback prompt for '%s' due to fetch error: %s", cache_key, diff --git a/tests/unit/test_prompt.py b/tests/unit/test_prompt.py index eadfb8221..890d58fd5 100644 --- a/tests/unit/test_prompt.py +++ b/tests/unit/test_prompt.py @@ -222,6 +222,21 @@ def test_throw_when_failing_fetch_and_no_cache(langfuse): assert "Prompt not found" in str(exc_info.value) +@pytest.mark.parametrize(("prompt_type", "fallback"), [("text", ""), ("chat", [])]) +def test_get_empty_fallback_when_fetch_fails(langfuse, prompt_type, fallback): + langfuse.api.prompts.get.side_effect = RuntimeError("Server unavailable") + + result = langfuse.get_prompt( + f"empty_fallback_{prompt_type}", + type=prompt_type, + fallback=fallback, + max_retries=0, + ) + + assert result.is_fallback + assert result.prompt == fallback + + def test_using_custom_prompt_timeouts(langfuse): prompt_name = "test_using_custom_prompt_timeouts" prompt = Prompt_Text(