| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9c13e44 commit 416f699
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,7 @@ | |||
| 39 | 39 | _agnosticcontextmanager, | |
| 40 | 40 | ) | |
| 41 | 41 | from packaging.version import Version | |
| 42 | + from pydantic import ValidationError | ||
| 42 | 43 | from typing_extensions import deprecated | |
| 43 | 44 | ||
| 44 | 45 | from langfuse._client.attributes import ( | |
@@ -1952,6 +1953,8 @@ def create_score( | |||
| 1952 | 1953 | force_sample=force_sample, | |
| 1953 | 1954 | ) | |
| 1954 | 1955 | ||
| 1956 | + except ValidationError as e: | ||
| 1957 | + raise ValueError(f"Invalid score parameters: {e}") from e | ||
| 1955 | 1958 | except Exception as e: | |
| 1956 | 1959 | langfuse_logger.exception( | |
| 1957 | 1960 | f"Error creating score: Failed to process score event for trace_id={trace_id}, name={name}. Error: {e}" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,36 @@ | |||
| 1 | + """Unit tests for create_score input validation. | ||
| 2 | + | ||
| 3 | + Ensures that programmer errors (None name or value) raise ValueError | ||
| 4 | + at the call site rather than being silently swallowed. | ||
| 5 | + """ | ||
| 6 | + | ||
| 7 | + import pytest | ||
| 8 | + | ||
| 9 | + from langfuse import Langfuse | ||
| 10 | + from langfuse._client.resource_manager import LangfuseResourceManager | ||
| 11 | + | ||
| 12 | + | ||
| 13 | + @pytest.fixture(autouse=True) | ||
| 14 | + def _clear_singleton(): | ||
| 15 | + yield | ||
| 16 | + with LangfuseResourceManager._lock: | ||
| 17 | + LangfuseResourceManager._instances.clear() | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + @pytest.fixture() | ||
| 21 | + def lf(): | ||
| 22 | + return Langfuse( | ||
| 23 | + public_key="pk-lf-test", | ||
| 24 | + secret_key="sk-lf-test", | ||
| 25 | + host="http://localhost:19999", | ||
| 26 | + ) | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + def test_create_score_raises_on_none_value(lf): | ||
| 30 | + with pytest.raises(ValueError, match="Invalid score parameters"): | ||
| 31 | + lf.create_score(name="accuracy", value=None, trace_id="fake-trace-id") | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + def test_create_score_raises_on_none_name(lf): | ||
| 35 | + with pytest.raises(ValueError, match="Invalid score parameters"): | ||
| 36 | + lf.create_score(name=None, value=0.9, trace_id="fake-trace-id") | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments