guan404ming commented on code in PR #71051:
URL: https://github.com/apache/airflow/pull/71051#discussion_r3758754361
##########
providers/common/ai/src/airflow/providers/common/ai/operators/llm_schema_compare.py:
##########
@@ -313,8 +324,32 @@ def execute(self, context: Context) -> dict[str, Any]:
self.log.info("Running LLM schema comparison...")
result = agent.run_sync(self.prompt, usage_limits=self.usage_limits)
log_run_summary(self.log, result)
+ output = result.output
- output_result = result.output.model_dump()
+ output_result = output.model_dump()
self.log.info("Schema comparison result: \n %s",
json.dumps(output_result, indent=2))
+ if self.require_approval:
+ severity_counts = Counter(mismatch.severity for mismatch in
output.mismatches)
+ summary = ", ".join(
+ f"{severity_counts[severity]} {severity}"
+ for severity in ("critical", "warning", "info")
+ if severity_counts[severity]
+ )
+ body = (
+ f"Compatible: {output.compatible}"
+ + (f" (mismatches: {summary})" if summary else "")
+ + f"\n\n```\nPrompt:
{self.prompt}\n\n{output.model_dump_json(indent=2)}\n```"
+ )
+ self.defer_for_approval(context, output, body=body) # type:
ignore[misc]
+
return output_result
+
+ def execute_complete(self, context: Context, generated_output: str, event:
dict[str, Any]) -> Any:
+ output = super().execute_complete(context, generated_output, event)
+ if not isinstance(output, dict):
Review Comment:
`rehydrate_pydantic_output` validates via
`TypeAdapter(SchemaCompareResult)`; it returns dict on success, raw str
otherwise. I think that's not that ideal to rely on the fallback thus I
reworked to make it explicitly validates via
SchemaCompareResult.model_validate_json, surfacing pydantic error details.
--
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]