From f9f2bec34a330b310f8283112a5c11910a8ef647 Mon Sep 17 00:00:00 2001 From: Jignesh Bhavani Date: Sun, 2 Aug 2026 02:57:06 +0530 Subject: [PATCH] fix: return false from isSupported for an unsupported output modality isSupported() is declared to return bool, but the RuntimeException from inferCapabilityFromOutputModalities() propagated out of it when the configured output modality had no matching capability. generateResult() still throws for the same modality, which is the behaviour testGenerateResultThrowsExceptionForUnsupportedOutputModality asserts. Fixes #270 --- src/Builders/PromptBuilder.php | 7 ++++++- tests/unit/Builders/PromptBuilderTest.php | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Builders/PromptBuilder.php b/src/Builders/PromptBuilder.php index 538392db..b4b189c3 100644 --- a/src/Builders/PromptBuilder.php +++ b/src/Builders/PromptBuilder.php @@ -613,7 +613,12 @@ public function isSupported(?CapabilityEnum $capability = null): bool // If still no capability, infer from output modalities if ($capability === null) { - $capability = $this->inferCapabilityFromOutputModalities(); + try { + $capability = $this->inferCapabilityFromOutputModalities(); + } catch (RuntimeException $e) { + // The output modality maps to no capability, so no model can support it. + return false; + } } } diff --git a/tests/unit/Builders/PromptBuilderTest.php b/tests/unit/Builders/PromptBuilderTest.php index 23a58959..c3b5b899 100644 --- a/tests/unit/Builders/PromptBuilderTest.php +++ b/tests/unit/Builders/PromptBuilderTest.php @@ -3864,6 +3864,19 @@ public function testIsSupportedWithInferredCapability(): void $this->assertTrue($builder->isSupported()); } + /** + * Tests isSupported returns false for an output modality without a matching capability. + * + * @return void + */ + public function testIsSupportedReturnsFalseForUnsupportedOutputModality(): void + { + $builder = new PromptBuilder($this->registry, 'Test prompt'); + $builder->asOutputModalities(ModalityEnum::document()); + + $this->assertFalse($builder->isSupported()); + } + /** * Tests isSupported method with inferred capability from model interfaces. *