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 @@ -3919,7 +3919,7 @@ def get_prompt(
fetch_timeout_seconds=fetch_timeout_seconds,
)
except Exception as e:
if fallback:
if fallback is not None:
langfuse_logger.warning(
f"Returning fallback prompt for '{cache_key}' due to fetch error: {e}"
)
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@ def test_throw_when_failing_fetch_and_no_cache(langfuse):
assert "Prompt not found" in str(exc_info.value)


def test_returns_empty_text_fallback_when_fetch_fails(langfuse):
prompt_name = "test_returns_empty_text_fallback_when_fetch_fails"

mock_server_call = langfuse.api.prompts.get
mock_server_call.side_effect = Exception("Prompt not found")

result = langfuse.get_prompt(prompt_name, fallback="", max_retries=0)

assert result.is_fallback
assert result.prompt == ""
mock_server_call.assert_called_once()


def test_using_custom_prompt_timeouts(langfuse):
prompt_name = "test_using_custom_prompt_timeouts"
prompt = Prompt_Text(
Expand Down