From c2d281e01b360ba0a2db177b90df6e7ba4df8501 Mon Sep 17 00:00:00 2001 From: Matthew Farrellee Date: Thu, 11 Sep 2025 07:48:19 -0400 Subject: [PATCH] chore(replay): improve replay robustness with un-validated construction (#3414) # What does this PR do? some providers do not produce spec compliant outputs. when this happens the replay infra will fail to construct the proper types and will return a dict to the client. the client likely does not expect a dict. this was discovered with tgi, which returns finish_reason="" when valid values are "stop", "length" or "content_filter" ## Test Plan ci --- llama_stack/testing/inference_recorder.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/llama_stack/testing/inference_recorder.py b/llama_stack/testing/inference_recorder.py index 298758c92..e78f493a6 100644 --- a/llama_stack/testing/inference_recorder.py +++ b/llama_stack/testing/inference_recorder.py @@ -105,8 +105,12 @@ def _deserialize_response(data: dict[str, Any]) -> Any: return cls.model_validate(data["__data__"]) except (ImportError, AttributeError, TypeError, ValueError) as e: - logger.warning(f"Failed to deserialize object of type {data['__type__']}: {e}") - return data["__data__"] + logger.warning(f"Failed to deserialize object of type {data['__type__']} with model_validate: {e}") + try: + return cls.model_construct(**data["__data__"]) + except Exception as e: + logger.warning(f"Failed to deserialize object of type {data['__type__']} with model_construct: {e}") + return data["__data__"] return data