Skip to content

Validate template fields after rendering in common.ai operators#70338

Merged
Lee-W merged 2 commits into
apache:mainfrom
1fanwang:fix-common-ai-init
Jul 24, 2026
Merged

Validate template fields after rendering in common.ai operators#70338
Lee-W merged 2 commits into
apache:mainfrom
1fanwang:fix-common-ai-init

Conversation

@1fanwang

Copy link
Copy Markdown
Contributor

message_history (AgentOperator) and source_path/file_type (DocumentLoaderOperator) are template fields, so they are rendered after __init__ runs. Both constructors validated them there, acting on the un-rendered Jinja expressions:

  • AgentOperator rejected message_history combined with enable_hitl_review. A templated message_history (e.g. "{{ ti.xcom_pull(...) }}") is a truthy string in __init__, so the check fired even when it renders to nothing.
  • DocumentLoaderOperator enforced the source_path / source_bytes / file_type combination, so a templated source_path couldn't resolve before the mutual-exclusivity check ran.

Move those checks into execute(), which runs after rendering. Constructor-only checks that read no template field (durable/code_mode) stay in __init__.

related: #70296

Testing Done

Updated the validation tests to drive execute(): test_message_history_with_hitl_review_raises and DocumentLoader's test_both_sources_raises / test_neither_source_raises / test_source_bytes_without_file_type_raises / test_empty_bytes_without_file_type_raises. Each fails on the pre-fix source (the constructor raises first, before the operator can render) and passes after. Full suites: test_agent.py + test_document_loader.py = 94 passed. validate_operators_init.py on both operators exits 0.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: GitHub Copilot CLI following the guidelines

message_history (AgentOperator) and source_path/file_type (DocumentLoaderOperator)
are template fields, rendered after __init__ runs. Both constructors validated
them there, acting on the un-rendered Jinja expressions: AgentOperator rejected
message_history + enable_hitl_review, and DocumentLoaderOperator enforced the
source_path/source_bytes/file_type combination. Move those checks into execute(),
which runs after rendering. Constructor-only checks that read no template field
(durable/code_mode) stay in __init__.

related: apache#70296
Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang
1fanwang force-pushed the fix-common-ai-init branch from 3dc0feb to ed33ae1 Compare July 24, 2026 00:56
@1fanwang
1fanwang marked this pull request as draft July 24, 2026 05:47
Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang
1fanwang marked this pull request as ready for review July 24, 2026 06:23
@shahar1 shahar1 removed the backport-to-v3-3-test Backport to v3-3-test label Jul 24, 2026
@Lee-W
Lee-W merged commit f24e8fe into apache:main Jul 24, 2026
135 of 140 checks passed
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.

3 participants