zylon-ai/private-gpt · error · CodeExecutionError
Code execution failed: {message}
Error message
Code execution failed: {message} What it means
The outer catch-all of _exec_code(): any exception during remote code execution — SQL pre-processing, code preparation, or self._client.run_code — is cleaned via get_clean_exception_info and re-raised as a pandasai CodeExecutionError. The '# noqa: B904' marks an intentional missing 'from e'. The interpolated message is the cleaned traceback of the underlying failure, frequently the user's generated Python erroring inside the sandbox.
Source
Thrown at private_gpt/components/tabular/pandasai_sandbox.py:302
)
processed_code = self._prepare_code_for_execution(code)
full_code = "\n\n".join(
part for part in (self._PREAMBLE, datasets_code, processed_code) if part
)
execution_result = self._run(
self._client.run_code(
full_code,
SandboxCodeOptions(language="python", timeout=self._timeout),
)
)
return self._process_execution_result(execution_result)
except Exception as e:
message = get_clean_exception_info(e)
logger.debug("Code execution failed: %s", message)
raise CodeExecutionError(f"Code execution failed: {message}") # noqa: B904
def _process_sql_queries(
self, sql_queries: list[str], environment: dict[str, Any]
) -> tuple[str, list[Exception]]:
if not sql_queries:
return "", []
temp_dir = f"/tmp/{self._user_id}"
datasets_map: dict[str, str] = {}
exceptions: list[Exception] = []
for sql_query in sql_queries:
execute_sql_query_func = environment.get("execute_sql_query")
if execute_sql_query_func is None:
logger.warning("execute_sql_query function not found in environment")
continue
try:View on GitHub (pinned to 4a030776a3)
Solutions
- Read the embedded cleaned traceback — it pinpoints the exact line of generated code that failed.
- For timeout: raise the sandbox timeout configuration for the adapter.
- For code errors: retry the analysis; add corrective feedback (the error text) into the follow-up prompt so the LLM fixes its code.
- For recurring schema mistakes: enrich the dataframe description passed to PandasAI.
- For transport errors: verify sandbox service health and retry once.
Example fix
# before
output = sandbox._exec_code(code, env)
# after
from pandasai.exceptions import CodeExecutionError
try:
output = sandbox._exec_code(code, env)
except CodeExecutionError as e:
logger.warning("Generated code failed once, retrying with feedback: %s", e)
code_v2 = regenerate_with_error_feedback(code, str(e))
output = sandbox._exec_code(code_v2, env) Defensive patterns
Strategy: retry
Try / catch
from pandasai.exceptions import CodeExecutionError
try:
out = sandbox._exec_code(code, env)
except CodeExecutionError as e:
out = sandbox._exec_code(regenerate_with_feedback(code, str(e)), env) Prevention
- Feed the cleaned traceback back to the LLM for self-correction
- Set a sandbox timeout comfortably above worst-case analysis time
- Keep sandbox library versions aligned with what generated code assumes
When it happens
Trigger: Generated Python raises at runtime in the remote sandbox (NameError, KeyError, pandas errors); the sandbox times out (SandboxCodeOptions timeout=self._timeout); transport errors from _client.run_code; chained from the SQL-preprocess ValueError at line 281.
Common situations: LLM-generated code referencing columns that do not exist in the dataframe; long-running analysis exceeding the configured sandbox timeout; network blips between app and sandbox; incompatible library versions inside the sandbox vs. what the generated code assumes.
Related errors
- Path '{canonical_path}' does not match any session mount.
- Failed to start sandbox: {e}
- Failed to execute some SQL queries: {', '.join(str(e) for e
- Query not found: {sql_query}
- Execution failed: {result.error or 'Unknown error'}
AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15).
Data as JSON: /api/errors/57aebdb50e20ead0.
Report an issue: GitHub.