Repository navigation
fix(client): apply mask to dataset and score payloads #1905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
asaraog
wants to merge
4
commits into
langfuse:main
Choose a base branch
from
asaraog:fix/mask-dataset-and-score-payloads
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
06dc752
test: mask applies to dataset and score payloads
asaraog 15d31ed
fix(client): apply mask to dataset and score payloads
asaraog 86fd1e8
test: enable tracing so create_score reaches the score queue
asaraog e9106d9
fix(client): serialize non-string masked score comments
asaraog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| from unittest.mock import Mock | ||
|
|
||
| from langfuse import Langfuse | ||
|
|
||
|
|
||
| def _client(): | ||
| client = Langfuse( | ||
| public_key="pk", | ||
| secret_key="sk", | ||
| host="https://mock-host.com", | ||
| tracing_enabled=False, | ||
| mask=lambda data: "masked", | ||
| ) | ||
| client.api = Mock() | ||
| client._resources.add_score_task = Mock() | ||
| return client | ||
|
|
||
|
|
||
| def test_create_dataset_item_masks_payload(): | ||
| client = _client() | ||
| client.create_dataset_item( | ||
| dataset_name="ds", input="secret", expected_output="secret", metadata="secret" | ||
| ) | ||
| kwargs = client.api.dataset_items.create.call_args.kwargs | ||
| assert (kwargs["input"], kwargs["expected_output"], kwargs["metadata"]) == ( | ||
| "masked", | ||
| "masked", | ||
| "masked", | ||
| ) | ||
|
|
||
|
|
||
| def test_create_dataset_masks_metadata(): | ||
| client = _client() | ||
| client.create_dataset(name="ds", metadata="secret") | ||
| assert client.api.datasets.create.call_args.kwargs["metadata"] == "masked" | ||
|
|
||
|
|
||
| def test_create_score_masks_comment(): | ||
| client = _client() | ||
| client._tracing_enabled = True # create_score is a no-op otherwise | ||
| client.create_score(name="s", value=1, trace_id="t" * 32, comment="secret") | ||
| assert ( | ||
| client._resources.add_score_task.call_args.args[0]["body"].comment == "masked" | ||
| ) | ||
|
|
||
|
|
||
| def test_create_score_serializes_non_string_masked_comment(): | ||
| client = _client() | ||
| client._tracing_enabled = True | ||
| client._mask = lambda data: {"redacted": True} | ||
| client.create_score(name="s", value=1, trace_id="t" * 32, comment="secret") | ||
| body = client._resources.add_score_task.call_args.args[0]["body"] | ||
| assert body.comment == '{"redacted": true}' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.