ColtenOuO commented on code in PR #70132:
URL: https://github.com/apache/airflow/pull/70132#discussion_r3627692315
##########
providers/common/ai/src/airflow/providers/common/ai/operators/agent.py:
##########
@@ -493,16 +492,11 @@ def execute(self, context: Context) -> Any:
output,
message_history=result.all_messages(),
)
- if isinstance(self.output_type, type) and
issubclass(self.output_type, BaseModel):
- return rehydrate_pydantic_output(
- self.output_type,
- result_str,
- serialize_output=self._serialize_model_output,
- )
- try:
- return json.loads(result_str)
- except (ValueError, TypeError):
- return result_str
+ return rehydrate_pydantic_output(
Review Comment:
In PR #70075 (merged), `rehydrate_pydantic_output` was updated to handle any
non-`str` output_type, not just `BaseModel` subclasses:
```python
if output_type is str:
return raw
try:
rehydrated = TypeAdapter(output_type).validate_json(raw)
except (ValidationError, ValueError, TypeError):
return raw
```
```bash
uv run --project providers/common/ai python -c "tic_output
from airflow.providers.common.ai.utils.output_type import
rehydrate_pydantic_outputtput=False)
result = rehydrate_pydantic_output(list[str], '[\"tag-a\",\"tag-b\"]',
serialize_output=False)
print(repr(result), type(result))
"
```
Output:
```
['tag-a', 'tag-b'] <class 'list'>
```
So I don't think the `json.loads` fallback needs to come back (?
Let me know what you think, or if I might have missed anything!
Thanks for your review!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]