Skip to content
Merged
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
15 changes: 14 additions & 1 deletion langfuse/api/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3635,7 +3635,7 @@ Use the `fields` parameter to control which observation fields are returned:
- `basic` - name, level, statusMessage, version, environment, bookmarked, public, userId, sessionId
- `time` - completionStartTime, createdAt, updatedAt
- `io` - input, output
- `metadata` - metadata
- `metadata` - metadata (truncated to 200 chars by default, use `expandMetadata` to get full values)
- `model` - providedModelName, internalModelId, modelParameters
- `usage` - usageDetails, costDetails, totalCost
- `prompt` - promptId, promptName, promptVersion
Expand Down Expand Up @@ -3699,6 +3699,19 @@ Example: "basic,usage,model"
<dl>
<dd>

**expand_metadata:** `typing.Optional[str]`

Comma-separated list of metadata keys to return non-truncated.
By default, metadata values over 200 characters are truncated.
Use this parameter to retrieve full values for specific keys.
Example: "key1,key2"

</dd>
</dl>

<dl>
<dd>

**limit:** `typing.Optional[int]` — Number of items to return per page. Maximum 1000, default 50.

</dd>
Expand Down
34 changes: 31 additions & 3 deletions langfuse/api/resources/commons/types/base_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,31 @@
class BaseScore(pydantic_v1.BaseModel):
id: str
trace_id: typing.Optional[str] = pydantic_v1.Field(alias="traceId", default=None)
"""
The trace ID associated with the score
"""

session_id: typing.Optional[str] = pydantic_v1.Field(
alias="sessionId", default=None
)
"""
The session ID associated with the score
"""

observation_id: typing.Optional[str] = pydantic_v1.Field(
alias="observationId", default=None
)
"""
The observation ID associated with the score
"""

dataset_run_id: typing.Optional[str] = pydantic_v1.Field(
alias="datasetRunId", default=None
)
"""
The dataset run ID associated with the score
"""

name: str
source: ScoreSource
timestamp: dt.datetime
Expand All @@ -28,8 +44,20 @@ class BaseScore(pydantic_v1.BaseModel):
author_user_id: typing.Optional[str] = pydantic_v1.Field(
alias="authorUserId", default=None
)
comment: typing.Optional[str] = None
metadata: typing.Optional[typing.Any] = None
"""
The user ID of the author
"""

comment: typing.Optional[str] = pydantic_v1.Field(default=None)
"""
Comment on the score
"""

metadata: typing.Any = pydantic_v1.Field()
"""
Metadata associated with the score
"""
Comment on lines +56 to +59
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Changed from Optional[typing.Any] with default=None to required typing.Any without default. Will fail validation if metadata is missing from API response.

Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/api/resources/commons/types/base_score.py
Line: 56:59

Comment:
**logic:** Changed from `Optional[typing.Any]` with `default=None` to required `typing.Any` without default. Will fail validation if `metadata` is missing from API response.

How can I resolve this? If you propose a fix, please make it concise.


config_id: typing.Optional[str] = pydantic_v1.Field(alias="configId", default=None)
"""
Reference a score config on a score. When set, config and score name must be equal and value must comply to optionally defined numerical range
Expand All @@ -40,7 +68,7 @@ class BaseScore(pydantic_v1.BaseModel):
The annotation queue referenced by the score. Indicates if score was initially created while processing annotation queue.
"""

environment: typing.Optional[str] = pydantic_v1.Field(default=None)
environment: str = pydantic_v1.Field()
"""
The environment from which this score originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
"""
Comment on lines +71 to 74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Changed from Optional[str] with default=None to required str without default. Will fail validation if environment is missing from API response.

Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/api/resources/commons/types/base_score.py
Line: 71:74

Comment:
**logic:** Changed from `Optional[str]` with `default=None` to required `str` without default. Will fail validation if `environment` is missing from API response.

How can I resolve this? If you propose a fix, please make it concise.

Expand Down
22 changes: 19 additions & 3 deletions langfuse/api/resources/commons/types/base_score_v_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,30 @@ class BaseScoreV1(pydantic_v1.BaseModel):
observation_id: typing.Optional[str] = pydantic_v1.Field(
alias="observationId", default=None
)
"""
The observation ID associated with the score
"""

timestamp: dt.datetime
created_at: dt.datetime = pydantic_v1.Field(alias="createdAt")
updated_at: dt.datetime = pydantic_v1.Field(alias="updatedAt")
author_user_id: typing.Optional[str] = pydantic_v1.Field(
alias="authorUserId", default=None
)
comment: typing.Optional[str] = None
metadata: typing.Optional[typing.Any] = None
"""
The user ID of the author
"""

comment: typing.Optional[str] = pydantic_v1.Field(default=None)
"""
Comment on the score
"""

metadata: typing.Any = pydantic_v1.Field()
"""
Metadata associated with the score
"""

config_id: typing.Optional[str] = pydantic_v1.Field(alias="configId", default=None)
"""
Reference a score config on a score. When set, config and score name must be equal and value must comply to optionally defined numerical range
Expand All @@ -34,7 +50,7 @@ class BaseScoreV1(pydantic_v1.BaseModel):
The annotation queue referenced by the score. Indicates if score was initially created while processing annotation queue.
"""

environment: typing.Optional[str] = pydantic_v1.Field(default=None)
environment: str = pydantic_v1.Field()
"""
The environment from which this score originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
"""
Expand Down
3 changes: 3 additions & 0 deletions langfuse/api/resources/commons/types/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Comment(pydantic_v1.BaseModel):
author_user_id: typing.Optional[str] = pydantic_v1.Field(
alias="authorUserId", default=None
)
"""
The user ID of the comment author
"""

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {
Expand Down
12 changes: 10 additions & 2 deletions langfuse/api/resources/commons/types/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@
class Dataset(pydantic_v1.BaseModel):
id: str
name: str
description: typing.Optional[str] = None
metadata: typing.Optional[typing.Any] = None
description: typing.Optional[str] = pydantic_v1.Field(default=None)
"""
Description of the dataset
"""

metadata: typing.Any = pydantic_v1.Field()
"""
Metadata associated with the dataset
"""

input_schema: typing.Optional[typing.Any] = pydantic_v1.Field(
alias="inputSchema", default=None
)
Expand Down
28 changes: 23 additions & 5 deletions langfuse/api/resources/commons/types/dataset_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,35 @@
class DatasetItem(pydantic_v1.BaseModel):
id: str
status: DatasetStatus
input: typing.Optional[typing.Any] = None
expected_output: typing.Optional[typing.Any] = pydantic_v1.Field(
alias="expectedOutput", default=None
)
metadata: typing.Optional[typing.Any] = None
input: typing.Any = pydantic_v1.Field()
"""
Input data for the dataset item
"""

expected_output: typing.Any = pydantic_v1.Field(alias="expectedOutput")
"""
Expected output for the dataset item
"""

metadata: typing.Any = pydantic_v1.Field()
"""
Metadata associated with the dataset item
"""
Comment on lines +14 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Changed input, expected_output, and metadata from optional to required without defaults. These fields now must be present in all API responses or deserialization will fail.

Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/api/resources/commons/types/dataset_item.py
Line: 14:27

Comment:
**logic:** Changed `input`, `expected_output`, and `metadata` from optional to required without defaults. These fields now must be present in all API responses or deserialization will fail.

How can I resolve this? If you propose a fix, please make it concise.


source_trace_id: typing.Optional[str] = pydantic_v1.Field(
alias="sourceTraceId", default=None
)
"""
The trace ID that sourced this dataset item
"""

source_observation_id: typing.Optional[str] = pydantic_v1.Field(
alias="sourceObservationId", default=None
)
"""
The observation ID that sourced this dataset item
"""

dataset_id: str = pydantic_v1.Field(alias="datasetId")
dataset_name: str = pydantic_v1.Field(alias="datasetName")
created_at: dt.datetime = pydantic_v1.Field(alias="createdAt")
Expand Down
2 changes: 1 addition & 1 deletion langfuse/api/resources/commons/types/dataset_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DatasetRun(pydantic_v1.BaseModel):
Description of the run
"""

metadata: typing.Optional[typing.Any] = pydantic_v1.Field(default=None)
metadata: typing.Any = pydantic_v1.Field()
"""
Metadata of the dataset run
"""
Expand Down
4 changes: 4 additions & 0 deletions langfuse/api/resources/commons/types/dataset_run_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class DatasetRunItem(pydantic_v1.BaseModel):
observation_id: typing.Optional[str] = pydantic_v1.Field(
alias="observationId", default=None
)
"""
The observation ID associated with this run item
"""

created_at: dt.datetime = pydantic_v1.Field(alias="createdAt")
updated_at: dt.datetime = pydantic_v1.Field(alias="updatedAt")

Expand Down
4 changes: 1 addition & 3 deletions langfuse/api/resources/commons/types/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ class Model(pydantic_v1.BaseModel):
Optional. Tokenizer to be applied to observations which match to this model. See docs for more details.
"""

tokenizer_config: typing.Optional[typing.Any] = pydantic_v1.Field(
alias="tokenizerConfig", default=None
)
tokenizer_config: typing.Any = pydantic_v1.Field(alias="tokenizerConfig")
"""
Optional. Configuration for the selected tokenizer. Needs to be JSON. See docs for more details.
"""
Expand Down
23 changes: 8 additions & 15 deletions langfuse/api/resources/commons/types/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from ....core.datetime_utils import serialize_datetime
from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1
from .map_value import MapValue
from .observation_level import ObservationLevel
from .usage import Usage

Expand Down Expand Up @@ -55,14 +54,12 @@ class Observation(pydantic_v1.BaseModel):
The model used for the observation
"""

model_parameters: typing.Optional[typing.Dict[str, MapValue]] = pydantic_v1.Field(
alias="modelParameters", default=None
)
model_parameters: typing.Any = pydantic_v1.Field(alias="modelParameters")
"""
The parameters of the model used for the observation
"""
Comment on lines +57 to 60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Changed from Optional[typing.Dict[str, MapValue]] with default=None to required typing.Any field. If the API response doesn't include modelParameters, Pydantic validation will fail during deserialization.

Suggested change
model_parameters: typing.Any = pydantic_v1.Field(alias="modelParameters")
"""
The parameters of the model used for the observation
"""
model_parameters: typing.Any = pydantic_v1.Field(default=None, alias="modelParameters")

Does the API always return modelParameters, metadata, input, output, usage, usageDetails, costDetails, and environment fields in observation responses?

Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/api/resources/commons/types/observation.py
Line: 57:60

Comment:
**logic:** Changed from `Optional[typing.Dict[str, MapValue]]` with `default=None` to required `typing.Any` field. If the API response doesn't include `modelParameters`, Pydantic validation will fail during deserialization.

```suggestion
    model_parameters: typing.Any = pydantic_v1.Field(default=None, alias="modelParameters")
```

 Does the API always return modelParameters, metadata, input, output, usage, usageDetails, costDetails, and environment fields in observation responses?

How can I resolve this? If you propose a fix, please make it concise.


input: typing.Optional[typing.Any] = pydantic_v1.Field(default=None)
input: typing.Any = pydantic_v1.Field()
"""
The input data of the observation
"""
Comment on lines +62 to 65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Changed from optional to required field without default value. This will cause validation errors if API responses don't include input.

Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/api/resources/commons/types/observation.py
Line: 62:65

Comment:
**logic:** Changed from optional to required field without default value. This will cause validation errors if API responses don't include `input`.

How can I resolve this? If you propose a fix, please make it concise.

Expand All @@ -72,17 +69,17 @@ class Observation(pydantic_v1.BaseModel):
The version of the observation
"""

metadata: typing.Optional[typing.Any] = pydantic_v1.Field(default=None)
metadata: typing.Any = pydantic_v1.Field()
"""
Additional metadata of the observation
"""
Comment on lines +72 to 75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Changed from optional to required without default. Will fail validation if metadata is missing from API response.

Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/api/resources/commons/types/observation.py
Line: 72:75

Comment:
**logic:** Changed from optional to required without default. Will fail validation if `metadata` is missing from API response.

How can I resolve this? If you propose a fix, please make it concise.


output: typing.Optional[typing.Any] = pydantic_v1.Field(default=None)
output: typing.Any = pydantic_v1.Field()
"""
The output data of the observation
"""
Comment on lines +77 to 80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Changed from optional to required without default. Will fail validation if output is missing from API response.

Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/api/resources/commons/types/observation.py
Line: 77:80

Comment:
**logic:** Changed from optional to required without default. Will fail validation if `output` is missing from API response.

How can I resolve this? If you propose a fix, please make it concise.


usage: typing.Optional[Usage] = pydantic_v1.Field(default=None)
usage: Usage = pydantic_v1.Field()
"""
(Deprecated. Use usageDetails and costDetails instead.) The usage data of the observation
"""
Comment on lines +82 to 85
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Changed from optional to required without default. Will fail validation if deprecated usage field is missing from API response.

Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/api/resources/commons/types/observation.py
Line: 82:85

Comment:
**logic:** Changed from optional to required without default. Will fail validation if deprecated `usage` field is missing from API response.

How can I resolve this? If you propose a fix, please make it concise.

Expand Down Expand Up @@ -111,21 +108,17 @@ class Observation(pydantic_v1.BaseModel):
The prompt ID associated with the observation
"""

usage_details: typing.Optional[typing.Dict[str, int]] = pydantic_v1.Field(
alias="usageDetails", default=None
)
usage_details: typing.Dict[str, int] = pydantic_v1.Field(alias="usageDetails")
"""
The usage details of the observation. Key is the name of the usage metric, value is the number of units consumed. The total key is the sum of all (non-total) usage metrics or the total value ingested.
"""
Comment on lines +111 to 114
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Changed from optional to required without default. Will fail validation if usageDetails is missing from API response.

Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/api/resources/commons/types/observation.py
Line: 111:114

Comment:
**logic:** Changed from optional to required without default. Will fail validation if `usageDetails` is missing from API response.

How can I resolve this? If you propose a fix, please make it concise.


cost_details: typing.Optional[typing.Dict[str, float]] = pydantic_v1.Field(
alias="costDetails", default=None
)
cost_details: typing.Dict[str, float] = pydantic_v1.Field(alias="costDetails")
"""
The cost details of the observation. Key is the name of the cost metric, value is the cost in USD. The total key is the sum of all (non-total) cost metrics or the total value ingested.
"""
Comment on lines +116 to 119
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Changed from optional to required without default. Will fail validation if costDetails is missing from API response.

Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/api/resources/commons/types/observation.py
Line: 116:119

Comment:
**logic:** Changed from optional to required without default. Will fail validation if `costDetails` is missing from API response.

How can I resolve this? If you propose a fix, please make it concise.


environment: typing.Optional[str] = pydantic_v1.Field(default=None)
environment: str = pydantic_v1.Field()
"""
The environment from which this observation originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
"""
Comment on lines +121 to 124
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Changed from optional to required without default. Will fail validation if environment is missing from API response.

Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/api/resources/commons/types/observation.py
Line: 121:124

Comment:
**logic:** Changed from optional to required without default. Will fail validation if `environment` is missing from API response.

How can I resolve this? If you propose a fix, please make it concise.

Expand Down
12 changes: 6 additions & 6 deletions langfuse/api/resources/commons/types/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class Score_Numeric(pydantic_v1.BaseModel):
alias="authorUserId", default=None
)
comment: typing.Optional[str] = None
metadata: typing.Optional[typing.Any] = None
metadata: typing.Any
config_id: typing.Optional[str] = pydantic_v1.Field(alias="configId", default=None)
queue_id: typing.Optional[str] = pydantic_v1.Field(alias="queueId", default=None)
environment: typing.Optional[str] = None
environment: str
Comment on lines +35 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Changed metadata from Optional[typing.Any] = None to required typing.Any without default, and environment from Optional[str] = None to required str without default. This pattern is repeated in all three Score variants (Numeric, Categorical, Boolean). API responses missing these fields will fail validation.

Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/api/resources/commons/types/score.py
Line: 35:38

Comment:
**logic:** Changed `metadata` from `Optional[typing.Any] = None` to required `typing.Any` without default, and `environment` from `Optional[str] = None` to required `str` without default. This pattern is repeated in all three Score variants (Numeric, Categorical, Boolean). API responses missing these fields will fail validation.

How can I resolve this? If you propose a fix, please make it concise.

data_type: typing.Literal["NUMERIC"] = pydantic_v1.Field(
alias="dataType", default="NUMERIC"
)
Expand Down Expand Up @@ -97,10 +97,10 @@ class Score_Categorical(pydantic_v1.BaseModel):
alias="authorUserId", default=None
)
comment: typing.Optional[str] = None
metadata: typing.Optional[typing.Any] = None
metadata: typing.Any
config_id: typing.Optional[str] = pydantic_v1.Field(alias="configId", default=None)
queue_id: typing.Optional[str] = pydantic_v1.Field(alias="queueId", default=None)
environment: typing.Optional[str] = None
environment: str
data_type: typing.Literal["CATEGORICAL"] = pydantic_v1.Field(
alias="dataType", default="CATEGORICAL"
)
Expand Down Expand Up @@ -162,10 +162,10 @@ class Score_Boolean(pydantic_v1.BaseModel):
alias="authorUserId", default=None
)
comment: typing.Optional[str] = None
metadata: typing.Optional[typing.Any] = None
metadata: typing.Any
config_id: typing.Optional[str] = pydantic_v1.Field(alias="configId", default=None)
queue_id: typing.Optional[str] = pydantic_v1.Field(alias="queueId", default=None)
environment: typing.Optional[str] = None
environment: str
data_type: typing.Literal["BOOLEAN"] = pydantic_v1.Field(
alias="dataType", default="BOOLEAN"
)
Expand Down
5 changes: 4 additions & 1 deletion langfuse/api/resources/commons/types/score_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ class ScoreConfig(pydantic_v1.BaseModel):
Configures custom categories for categorical scores
"""

description: typing.Optional[str] = None
description: typing.Optional[str] = pydantic_v1.Field(default=None)
"""
Description of the score config
"""

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {
Expand Down
12 changes: 6 additions & 6 deletions langfuse/api/resources/commons/types/score_v_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class ScoreV1_Numeric(pydantic_v1.BaseModel):
alias="authorUserId", default=None
)
comment: typing.Optional[str] = None
metadata: typing.Optional[typing.Any] = None
metadata: typing.Any
config_id: typing.Optional[str] = pydantic_v1.Field(alias="configId", default=None)
queue_id: typing.Optional[str] = pydantic_v1.Field(alias="queueId", default=None)
environment: typing.Optional[str] = None
environment: str
data_type: typing.Literal["NUMERIC"] = pydantic_v1.Field(
alias="dataType", default="NUMERIC"
)
Expand Down Expand Up @@ -85,10 +85,10 @@ class ScoreV1_Categorical(pydantic_v1.BaseModel):
alias="authorUserId", default=None
)
comment: typing.Optional[str] = None
metadata: typing.Optional[typing.Any] = None
metadata: typing.Any
config_id: typing.Optional[str] = pydantic_v1.Field(alias="configId", default=None)
queue_id: typing.Optional[str] = pydantic_v1.Field(alias="queueId", default=None)
environment: typing.Optional[str] = None
environment: str
data_type: typing.Literal["CATEGORICAL"] = pydantic_v1.Field(
alias="dataType", default="CATEGORICAL"
)
Expand Down Expand Up @@ -144,10 +144,10 @@ class ScoreV1_Boolean(pydantic_v1.BaseModel):
alias="authorUserId", default=None
)
comment: typing.Optional[str] = None
metadata: typing.Optional[typing.Any] = None
metadata: typing.Any
config_id: typing.Optional[str] = pydantic_v1.Field(alias="configId", default=None)
queue_id: typing.Optional[str] = pydantic_v1.Field(alias="queueId", default=None)
environment: typing.Optional[str] = None
environment: str
data_type: typing.Literal["BOOLEAN"] = pydantic_v1.Field(
alias="dataType", default="BOOLEAN"
)
Expand Down
Loading
Loading