From b0364572b29390bd90e2696fc7cbd0286ba691ca Mon Sep 17 00:00:00 2001 From: Matthew Farrellee Date: Thu, 11 Sep 2025 01:01:01 -0400 Subject: [PATCH] chore(replay): improve replay robustness with un-validated construction 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" --- 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