diff --git a/packages/traceloop-sdk/tests/test_user_feedback.py b/packages/traceloop-sdk/tests/test_user_feedback.py index 354d576ada..be8aed3ca6 100644 --- a/packages/traceloop-sdk/tests/test_user_feedback.py +++ b/packages/traceloop-sdk/tests/test_user_feedback.py @@ -37,10 +37,11 @@ def test_user_feedback_initialization(mock_http): def test_create_basic_feedback(user_feedback: UserFeedback, mock_http: Mock): """Test creating basic user feedback""" - user_feedback.create( + result = user_feedback.create( annotation_task="task_123", entity_id="instance_456", tags={"sentiment": "positive"} ) + assert result == {"status": "success"} mock_http.post.assert_called_once_with( "annotation-tasks/task_123/annotations", { @@ -60,8 +61,9 @@ def test_create_feedback_complex_tags(user_feedback: UserFeedback, mock_http: Mo """Test creating user feedback with complex tags""" tags = {"sentiment": "positive", "relevance": 0.95, "tones": ["happy", "nice"]} - user_feedback.create(annotation_task="task_123", entity_id="instance_456", tags=tags) + result = user_feedback.create(annotation_task="task_123", entity_id="instance_456", tags=tags) + assert result == {"status": "success"} mock_http.post.assert_called_once_with( "annotation-tasks/task_123/annotations", { @@ -87,3 +89,14 @@ def test_create_feedback_parameter_validation(user_feedback: UserFeedback): with pytest.raises(ValueError, match="tags cannot be empty"): user_feedback.create(annotation_task="task_123", entity_id="instance_456", tags={}) + + +def test_create_feedback_returns_none_when_write_fails(user_feedback: UserFeedback, mock_http: Mock): + """Test feedback submission returns the HTTP client's failure signal.""" + mock_http.post.return_value = None + + result = user_feedback.create( + annotation_task="task_123", entity_id="instance_456", tags={"sentiment": "positive"} + ) + + assert result is None diff --git a/packages/traceloop-sdk/traceloop/sdk/annotation/base_annotation.py b/packages/traceloop-sdk/traceloop/sdk/annotation/base_annotation.py index b9e515ca0c..04ae326719 100644 --- a/packages/traceloop-sdk/traceloop/sdk/annotation/base_annotation.py +++ b/packages/traceloop-sdk/traceloop/sdk/annotation/base_annotation.py @@ -1,4 +1,4 @@ -from typing import Dict, Any +from typing import Any, Dict from ..client.http import HTTPClient @@ -23,7 +23,7 @@ def create( annotation_task: str, entity_id: str, tags: Dict[str, Any], - ) -> None: + ) -> Any: """Create an user feedback annotation for a specific task. Args: @@ -34,6 +34,10 @@ def create( tags (Dict[str, Any]): Dictionary containing the tags to be reported. Should match the tags defined in the annotation task + Returns: + The API response returned by the annotation write request, or None + when the underlying HTTP client could not complete the write. + Example: ```python client = Client(api_key="your-key") @@ -56,7 +60,7 @@ def create( if not tags: raise ValueError("tags cannot be empty") - self._http.post( + return self._http.post( f"annotation-tasks/{annotation_task}/annotations", { "entity_instance_id": entity_id, diff --git a/packages/traceloop-sdk/traceloop/sdk/annotation/user_feedback.py b/packages/traceloop-sdk/traceloop/sdk/annotation/user_feedback.py index 8dba6cf07b..d5c60b7a8a 100644 --- a/packages/traceloop-sdk/traceloop/sdk/annotation/user_feedback.py +++ b/packages/traceloop-sdk/traceloop/sdk/annotation/user_feedback.py @@ -13,7 +13,7 @@ def create( annotation_task: str, entity_id: str, tags: Dict[str, Any], - ) -> None: + ) -> Any: """Create an annotation for a specific task. Args: @@ -24,6 +24,10 @@ def create( tags (Dict[str, Any]): Dictionary containing the tags to be reported. Should match the tags defined in the annotation task + Returns: + The API response returned by the annotation write request, or None + when the underlying HTTP client could not complete the write. + Example: ```python client = Client(api_key="your-key")