Skip to content

Add input/output modality validation to TargetRequirements.validate()#1778

Merged
hannahwestra25 merged 3 commits into
microsoft:mainfrom
hannahwestra25:hannahwestra25/fix-modality-validation-in-target-requir
May 22, 2026
Merged

Add input/output modality validation to TargetRequirements.validate()#1778
hannahwestra25 merged 3 commits into
microsoft:mainfrom
hannahwestra25:hannahwestra25/fix-modality-validation-in-target-requir

Conversation

@hannahwestra25
Copy link
Copy Markdown
Contributor

@hannahwestra25 hannahwestra25 commented May 21, 2026

Problem

TargetRequirements.validate() checks boolean capabilities (MULTI_TURN, EDITABLE_HISTORY, etc.) but does not check modalities. A consumer that requires image input can be wired to a text-only target with no error at construction time -- the mismatch is only caught at runtime in _validate_request.

Solution

Add two optional fields to TargetRequirements:

  • required_input_modalities: frozenset[frozenset[PromptDataType]]
  • required_output_modalities: frozenset[frozenset[PromptDataType]]

validate() checks that each required modality combo is covered by at least one of the target's supported combos (superset check), consistent with the runtime check in _validate_request.

Both fields default to frozenset() so existing consumers are unaffected.

Test coverage

7 new tests covering match, superset pass-through, missing input/output errors, mixed modality + capability error aggregation, and backward compatibility.

hannahwestra25 and others added 2 commits May 21, 2026 17:25
TargetRequirements.validate() previously only checked boolean capabilities
(required / native_required). It did not verify that the target's
input_modalities and output_modalities satisfy consumer expectations.

Add required_input_modalities and required_output_modalities fields, and
extend validate() to check each required modality combo is covered by at
least one of the target's supported combos.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Move PromptDataType import into TYPE_CHECKING block (TC001)
- Use list comprehension in _check_modalities (PERF401)
- Apply ruff formatting
- Update 0_prompt_targets.md, 6_1_target_capabilities.py/.ipynb to
  document required_input_modalities / required_output_modalities

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hannahwestra25 hannahwestra25 force-pushed the hannahwestra25/fix-modality-validation-in-target-requir branch from 1f3dacd to 74b8e41 Compare May 21, 2026 21:44
@hannahwestra25 hannahwestra25 marked this pull request as ready for review May 21, 2026 21:51
Copy link
Copy Markdown
Contributor

@behnam-o behnam-o left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!

@hannahwestra25 hannahwestra25 added this pull request to the merge queue May 22, 2026
Merged via the queue into microsoft:main with commit 484f0d3 May 22, 2026
48 checks passed
@hannahwestra25 hannahwestra25 deleted the hannahwestra25/fix-modality-validation-in-target-requir branch May 22, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants