8484 DeleteDatasetRunResponse ,
8585 PaginatedDatasetRuns ,
8686)
87+ from langfuse .api .resources .commons .errors .not_found_error import NotFoundError
8788from langfuse .api .resources .ingestion .types .score_body import ScoreBody
8889from langfuse .api .resources .prompts .types import (
8990 CreatePromptRequest_Chat ,
@@ -1976,6 +1977,7 @@ def create_score(
19761977 comment : Optional [str ] = None ,
19771978 config_id : Optional [str ] = None ,
19781979 metadata : Optional [Any ] = None ,
1980+ timestamp : Optional [datetime ] = None ,
19791981 ) -> None : ...
19801982
19811983 @overload
@@ -1993,6 +1995,7 @@ def create_score(
19931995 comment : Optional [str ] = None ,
19941996 config_id : Optional [str ] = None ,
19951997 metadata : Optional [Any ] = None ,
1998+ timestamp : Optional [datetime ] = None ,
19961999 ) -> None : ...
19972000
19982001 def create_score (
@@ -2009,6 +2012,7 @@ def create_score(
20092012 comment : Optional [str ] = None ,
20102013 config_id : Optional [str ] = None ,
20112014 metadata : Optional [Any ] = None ,
2015+ timestamp : Optional [datetime ] = None ,
20122016 ) -> None :
20132017 """Create a score for a specific trace or observation.
20142018
@@ -2027,6 +2031,7 @@ def create_score(
20272031 comment: Optional comment or explanation for the score
20282032 config_id: Optional ID of a score config defined in Langfuse
20292033 metadata: Optional metadata to be attached to the score
2034+ timestamp: Optional timestamp for the score (defaults to current UTC time)
20302035
20312036 Example:
20322037 ```python
@@ -2073,7 +2078,7 @@ def create_score(
20732078 event = {
20742079 "id" : self .create_trace_id (),
20752080 "type" : "score-create" ,
2076- "timestamp" : _get_timestamp (),
2081+ "timestamp" : timestamp or _get_timestamp (),
20772082 "body" : new_body ,
20782083 }
20792084
@@ -3327,20 +3332,28 @@ def create_dataset(
33273332 name : str ,
33283333 description : Optional [str ] = None ,
33293334 metadata : Optional [Any ] = None ,
3335+ input_schema : Optional [Any ] = None ,
3336+ expected_output_schema : Optional [Any ] = None ,
33303337 ) -> Dataset :
33313338 """Create a dataset with the given name on Langfuse.
33323339
33333340 Args:
33343341 name: Name of the dataset to create.
33353342 description: Description of the dataset. Defaults to None.
33363343 metadata: Additional metadata. Defaults to None.
3344+ input_schema: JSON Schema for validating dataset item inputs. When set, all new items will be validated against this schema.
3345+ expected_output_schema: JSON Schema for validating dataset item expected outputs. When set, all new items will be validated against this schema.
33373346
33383347 Returns:
33393348 Dataset: The created dataset as returned by the Langfuse API.
33403349 """
33413350 try :
33423351 body = CreateDatasetRequest (
3343- name = name , description = description , metadata = metadata
3352+ name = name ,
3353+ description = description ,
3354+ metadata = metadata ,
3355+ inputSchema = input_schema ,
3356+ expectedOutputSchema = expected_output_schema ,
33443357 )
33453358 langfuse_logger .debug (f"Creating datasets { body } " )
33463359
@@ -3674,6 +3687,14 @@ def fetch_prompts() -> Any:
36743687
36753688 return prompt
36763689
3690+ except NotFoundError as not_found_error :
3691+ langfuse_logger .warning (
3692+ f"Prompt '{ cache_key } ' not found during refresh, evicting from cache."
3693+ )
3694+ if self ._resources is not None :
3695+ self ._resources .prompt_cache .delete (cache_key )
3696+ raise not_found_error
3697+
36773698 except Exception as e :
36783699 langfuse_logger .error (
36793700 f"Error while fetching prompt '{ cache_key } ': { str (e )} "
0 commit comments