Skip to content

Move template-field validation out of AnthropicAgentSessionOperator __init__ - #70432

Merged
shahar1 merged 1 commit into
apache:mainfrom
bramhanandlingala:fix/70296-2
Jul 26, 2026
Merged

Move template-field validation out of AnthropicAgentSessionOperator __init__#70432
shahar1 merged 1 commit into
apache:mainfrom
bramhanandlingala:fix/70296-2

Conversation

@bramhanandlingala

@bramhanandlingala bramhanandlingala commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

AnthropicAgentSessionOperator.__init__ validated message and outcome
before Jinja templating runs, even though both are template_fields. A
templated outcome (e.g. outcome="{{ params.outcome }}") would crash
at DAG-parse time with AttributeError: 'str' object has no attribute 'keys', before rendering ever gets a chance to resolve it to a real dict.

Fix

providers/anthropic/src/airflow/providers/anthropic/operators/agent.py:

  • __init__ now only does plain assignments.
  • The two validation checks (message/outcome mutual exclusivity, and
    outcome requiring description + rubric) moved to the top of
    execute(), after templating has run.

Testing

providers/anthropic/tests/unit/anthropic/operators/test_agent.py:

  • Updated test_requires_exactly_one_of_message_or_outcome and
    test_outcome_requires_description_and_rubric to construct the operator
    first, then assert the ValueError is raised on .execute() instead of
    at construction.
  • Added test_init_does_not_validate_message_or_outcome to lock in that
    __init__ accepts any combination without raising.

Exemption list

Removed AnthropicAgentSessionOperator's entry from
scripts/ci/prek/validate_operators_init_exemptions.txt, as required by
the burn-down rule.

Related to #70296

Gen-AI disclosure: I used a generative AI tool to help identify the root
cause, write tests, and draft the PR description. I reviewed, tested, and
verified all changes locally before submitting.

Was generative AI tooling used to co-author this PR?
  • Yes — Claude

Generated-by: Claude following the guidelines

@shahar1 shahar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shahar1
shahar1 dismissed their stale review July 26, 2026 05:45

Concerns addressed

@shahar1 shahar1 changed the title Move template-field validation out of AnthropicAgentSessionOperator _… Move template-field validation out of AnthropicAgentSessionOperator Jul 26, 2026
@shahar1 shahar1 changed the title Move template-field validation out of AnthropicAgentSessionOperator Move template-field validation out of AnthropicAgentSessionOperator __init__ Jul 26, 2026
@shahar1 shahar1 changed the title Move template-field validation out of AnthropicAgentSessionOperator __init__ Move template-field validation out of AnthropicAgentSessionOperator __init__() Jul 26, 2026
@shahar1 shahar1 changed the title Move template-field validation out of AnthropicAgentSessionOperator __init__() Move template-field validation out of AnthropicAgentSessionOperator __init__ Jul 26, 2026
@shahar1
shahar1 merged commit 9b72aed into apache:main Jul 26, 2026
79 checks passed
Kunal8954 pushed a commit to Kunal8954/airflow that referenced this pull request Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants