Skip to content

Commit 8a87c39

Browse files
Validate input in chunk_and_stitch_embed
An empty input reaching the shared helper fell through to validate_embedding_response and raised provider_invalid_response ("provider returned no vectors"), misclassifying a caller-side invalid request as an invalid response. Call validate_embedding_input up front so an empty (or non-string) input raises provider_invalid_request. Providers already validate before the helper; this protects a direct/future caller.
1 parent b0b1d2c commit 8a87c39

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/openarmature/retrieval/_wire.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from openarmature.llm.errors import ProviderInvalidResponse
1717

18-
from .provider import validate_embedding_response
18+
from .provider import validate_embedding_input, validate_embedding_response
1919
from .response import EmbeddingResponse, EmbeddingUsage
2020

2121

@@ -122,6 +122,12 @@ async def chunk_and_stitch_embed(
122122
# (cap == 0) or a misleading empty-stitched validation failure (cap < 0).
123123
if cap <= 0:
124124
raise ValueError(f"cap must be positive (got {cap})")
125+
# Validate the input up front (empty / non-string) so an empty input raises
126+
# provider_invalid_request -- the caller-side contract error -- rather than
127+
# falling through to a misclassified provider_invalid_response from the
128+
# empty stitched-count check. Providers already call this before the helper;
129+
# this protects a direct / future caller.
130+
validate_embedding_input(input_strings)
125131
stitched_vectors: list[list[float]] = []
126132
chunk_bodies: list[Any] = []
127133
input_tokens_total: int | None = None

tests/unit/test_retrieval_provider.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,18 @@ async def _noop(chunk: list[str]) -> tuple[list[list[float]], None, None, list[A
15051505
await chunk_and_stitch_embed(["a"], model="m", cap=bad_cap, embed_chunk=_noop)
15061506

15071507

1508+
async def test_chunk_and_stitch_embed_rejects_empty_input() -> None:
1509+
# An empty input reaching the helper is a caller error -> provider_invalid_request
1510+
# (validate_embedding_input), NOT a misclassified provider_invalid_response.
1511+
from openarmature.retrieval._wire import chunk_and_stitch_embed
1512+
1513+
async def _noop(chunk: list[str]) -> tuple[list[list[float]], None, None, list[Any]]:
1514+
return [], None, None, []
1515+
1516+
with pytest.raises(ProviderInvalidRequest):
1517+
await chunk_and_stitch_embed([], model="m", cap=4, embed_chunk=_noop)
1518+
1519+
15081520
# --- /rerank wire + chunk-and-stitch ----------------------------------------
15091521

15101522

0 commit comments

Comments
 (0)