Skip to content

fix(openai): validate encoder input before embeddings call#657

Open
pandego wants to merge 1 commit intoaurelio-labs:mainfrom
pandego:fix/466-bm25encoder-nltk-guidance
Open

fix(openai): validate encoder input before embeddings call#657
pandego wants to merge 1 commit intoaurelio-labs:mainfrom
pandego:fix/466-bm25encoder-nltk-guidance

Conversation

@pandego
Copy link
Contributor

@pandego pandego commented Mar 7, 2026

Summary

  • add input validation to OpenAIEncoder before calling the embeddings API
  • fail fast with clear ValueError messages for:
    • empty input list
    • non-string list elements
    • blank or whitespace-only strings
  • keep retry and API behavior unchanged for valid input

Why

Issue #530 reports OpenAI returning 400 '$.input' is invalid, which is difficult to diagnose from user code. This change catches common invalid input shapes earlier and surfaces clearer, actionable errors before the API call.

Validation

  • uv run pytest tests/unit/encoders/test_openai.py
  • result: 16 passed

Closes #530

@jamescalam
Copy link
Member

good call - I'll have workflows run and merge when complete

@pandego
Copy link
Contributor Author

pandego commented Mar 12, 2026

Thanks! I checked the failing CI jobs.

The current failures are Pinecone router tests in tests/unit/test_router.py, and they appear unrelated to this patch. This PR only changes semantic_router/encoders/openai.py and tests/unit/encoders/test_openai.py.

@jamescalam
Copy link
Member

yeah they're unrelated - I need to double check our CI pipeline envs @pandego

@pandego pandego force-pushed the fix/466-bm25encoder-nltk-guidance branch from 40161c4 to be4578c Compare March 14, 2026 07:56
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.

OpenAI BadRequestError: '$.input' is invalid in semantic_router OpenAI encoder

2 participants