[Misc] Replace assert with proper exceptions for security and validation in pooling (#43286)

Signed-off-by: Taneem Ibrahim <taneem.ibrahim@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Nick Hill <nickhill123@gmail.com>
This commit is contained in:
Taneem Ibrahim
2026-05-22 18:43:33 +08:00
committed by GitHub
co-authored by Claude Opus 4.6 Nick Hill
parent d3d1cf6972
commit b3c7ffcab8
4 changed files with 37 additions and 17 deletions
+9 -5
View File
@@ -110,7 +110,8 @@ class PoolingParams(
if pooler_config is None:
return
assert self.task is not None, "task must be set"
if self.task is None:
raise ValueError("task must be set before merging parameters")
valid_parameters = self.valid_parameters[self.task]
for k in valid_parameters:
@@ -189,7 +190,8 @@ class PoolingParams(
raise ValueError(f"Unknown pooling task: {self.task!r}")
def _verify_valid_parameters(self):
assert self.task is not None, "task must be set"
if self.task is None:
raise ValueError("task must be set before verifying parameters")
valid_parameters = self.valid_parameters[self.task]
invalid_parameters = []
for k in self.all_parameters:
@@ -221,6 +223,8 @@ class PoolingParams(
)
def __post_init__(self) -> None:
assert self.output_kind == RequestOutputKind.FINAL_ONLY, (
"For pooling output_kind has to be FINAL_ONLY"
)
if self.output_kind != RequestOutputKind.FINAL_ONLY:
raise ValueError(
"For pooling output_kind has to be FINAL_ONLY, "
f"got {self.output_kind!r}"
)