Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion langfuse/_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading