Error while passing empty string to openai client in preprocessing
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Users/merajul.arefin-macbook/Documents/research/Alpha-SQL/alphasql/runner/preprocessor.py", line 512, in <module>
predicted_relevant_values_for_all_tasks = preprocessor.get_relevant_values_for_all_tasks()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/merajul.arefin-macbook/Documents/research/Alpha-SQL/alphasql/runner/preprocessor.py", line 319, in get_relevant_values_for_all_tasks
relevant_values_for_all_tasks = list(
^^^^^
File "/Users/merajul.arefin-macbook/miniconda3/envs/alphasql/lib/python3.11/site-packages/tqdm/std.py", line 1181, in __iter__
for obj in iterable:
File "/Users/merajul.arefin-macbook/miniconda3/envs/alphasql/lib/python3.11/concurrent/futures/_base.py", line 619, in result_iterator
yield _result_or_cancel(fs.pop())
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/merajul.arefin-macbook/miniconda3/envs/alphasql/lib/python3.11/concurrent/futures/_base.py", line 317, in _result_or_cancel
return fut.result(timeout)
^^^^^^^^^^^^^^^^^^^
File "/Users/merajul.arefin-macbook/miniconda3/envs/alphasql/lib/python3.11/concurrent/futures/_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/Users/merajul.arefin-macbook/miniconda3/envs/alphasql/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/Users/merajul.arefin-macbook/miniconda3/envs/alphasql/lib/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/merajul.arefin-macbook/Documents/research/Alpha-SQL/alphasql/runner/preprocessor.py", line 283, in get_relevant_values_for_task
embedding_similarity_candidate_values = self.filter_candidate_values_by_embedding_similarity(edit_similarity_candidate_values, self.embedding_similarity_threshold)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/merajul.arefin-macbook/Documents/research/Alpha-SQL/alphasql/runner/preprocessor.py", line 231, in filter_candidate_values_by_embedding_similarity
embeddings = EMBEDDING_MODEL_CALLABLE.embed_documents(to_embeded_list)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/merajul.arefin-macbook/Documents/research/Alpha-SQL/alphasql/llm_call/embedding_utils.py", line 73, in embed_documents
response = self.client.embeddings.create(model=self.model, input=texts)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/merajul.arefin-macbook/miniconda3/envs/alphasql/lib/python3.11/site-packages/openai/resources/embeddings.py", line 136, in create
return self._post(
^^^^^^^^^^^
File "/Users/merajul.arefin-macbook/miniconda3/envs/alphasql/lib/python3.11/site-packages/openai/_base_client.py", line 1332, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/merajul.arefin-macbook/miniconda3/envs/alphasql/lib/python3.11/site-packages/openai/_base_client.py", line 1105, in request
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid 'input[0]': input cannot be an empty string.", 'type': 'invalid_request_error', 'param': None, 'code': None}}
Getting this error while running preprocessing script
Thanks for the report. I traced this to the relevant-value retrieval step in preprocessing, not to OpenAI client initialization.
The failing path is:
get_relevant_values_for_task()collects keywords and queries the LSH index.filter_candidate_values_by_embedding_similarity()builds one embedding batch from every candidatevalueandquery.- That batch is passed directly to
client.embeddings.create(..., input=texts).
The problem is that the batch can contain "" or whitespace-only text. OpenAI's embeddings endpoint rejects empty strings, which is why the request fails with:
Invalid 'input[0]': input cannot be an empty string.
There are two ways empty text can enter this path:
- The LSH index was built from database values using
WHERE column IS NOT NULL, which excludesNULLbut still allows empty strings. - Keyword expansion can also create empty tokens after splitting and stripping generated keywords.
The fix is to filter empty/whitespace-only strings at both boundaries:
- when loading distinct text values for the LSH index, exclude
trim(cast(value as text)) = ''; - after keyword expansion, drop empty keywords;
- before calling the embedding model, drop candidates whose
queryorvalueis empty afterstrip(), and return an empty result if no valid candidates remain.
One operational note: if preprocessing has already created lsh_index/ directories, those indexes may still contain empty-string values. After applying the fix, delete the existing per-database lsh_index/ directories and rerun preprocessing so the indexes are rebuilt from filtered values.
Fixed in commit 216e61f (Fix empty embedding inputs during preprocessing) and pushed to master.
The preprocessing pipeline now filters empty/whitespace-only strings before they can reach the embeddings API:
- LSH index construction excludes empty text values from database columns.
- Keyword expansion drops empty tokens.
- Embedding similarity filtering drops candidates with empty
queryorvalue, and returns no candidates if nothing valid remains.
If you already ran preprocessing before this fix, please delete the generated per-database lsh_index/ directories and rerun preprocessing so the cached indexes are rebuilt without empty values.