Open ShaneJIan opened 3 months ago
I thought of raising a custom exception when the result is not valid JSON.
I don't think we should return None or a default value because the goal is to actually create an instance of target_cls.
If the data is not a JSON string, our only choice is to fail and let the upstream application deal with that case (retry, change the context window, ...)
Does a custom exception make sense, something like InvalidLLMJSONResponse
?
BaseParser.java def deserialize(self, json_str): try: attributes = dirtyjson.loads(json_str) return from_dict(self.target_cls, attributes) except dirtyjson.error.Error as e: print(f"Failed to parse JSON string: {e}")
handle the error appropriately, perhaps returning None or a default value