@@ -246,6 +246,34 @@ def wrapper(wrapped: Any, instance: Any, args: Any, kwargs: Any) -> Any:
246246 return _with_langfuse
247247
248248
249+ def _extract_responses_prompt (kwargs : Any ) -> Any :
250+ input_value = kwargs .get ("input" , None )
251+ instructions = kwargs .get ("instructions" , None )
252+
253+ if isinstance (input_value , NotGiven ):
254+ input_value = None
255+
256+ if isinstance (instructions , NotGiven ):
257+ instructions = None
258+
259+ if instructions is None :
260+ return input_value
261+
262+ if input_value is None :
263+ return {"instructions" : instructions }
264+
265+ if isinstance (input_value , str ):
266+ return [
267+ {"role" : "system" , "content" : instructions },
268+ {"role" : "user" , "content" : input_value },
269+ ]
270+
271+ if isinstance (input_value , list ):
272+ return [{"role" : "system" , "content" : instructions }, * input_value ]
273+
274+ return {"instructions" : instructions , "input" : input_value }
275+
276+
249277def _extract_chat_prompt (kwargs : Any ) -> Any :
250278 """Extracts the user input from prompts. Returns an array of messages or dict with messages and functions"""
251279 prompt = {}
@@ -403,7 +431,7 @@ def _get_langfuse_data_from_kwargs(resource: OpenAiDefinition, kwargs: Any) -> A
403431 if resource .type == "completion" :
404432 prompt = kwargs .get ("prompt" , None )
405433 elif resource .object == "Responses" or resource .object == "AsyncResponses" :
406- prompt = kwargs . get ( "input" , None )
434+ prompt = _extract_responses_prompt ( kwargs )
407435 elif resource .type == "chat" :
408436 prompt = _extract_chat_prompt (kwargs )
409437 elif resource .type == "embedding" :
0 commit comments