Skip to content

fix: improve Python step error messages for better debugging#6184

Closed
DragonBot00 wants to merge 1 commit intokeephq:mainfrom
DragonBot00:fix/python-step-error-clarity
Closed

fix: improve Python step error messages for better debugging#6184
DragonBot00 wants to merge 1 commit intokeephq:mainfrom
DragonBot00:fix/python-step-error-clarity

Conversation

@DragonBot00
Copy link
Copy Markdown
Contributor

Summary

Fixes #5327

Problem

When a workflow uses a Python step provider and the code contains a syntax error, the error message was extremely unclear. Instead of surfacing the actual Python SyntaxError, Keep would dump the entire rendered provider config string (including unrelated details like Kibana endpoints, ports, and validation tokens) as the error message.

Example of the confusing error (before this fix):
\
Got SyntaxError while parsing token 'keep.kb.us-central1.gcp.cloud.es.io', 'validation': 'any_http_url'...
\\

This message has nothing to do with the user's Python code and is actively misleading.

Root Cause

In \python_provider.py, the _query\ method calls \self.io_handler.parse(code)\ to render Jinja templates inside the code string. When this rendering fails with a \SyntaxError\ (or when the rendered code fails inside \eval()), the exception message includes the raw rendered token — which can contain provider configuration data (URLs, authentication tokens, ports, etc.) from the workflow context.

Fix

  • Pre-validation: Added a \compile()\ check on the raw user code before template rendering to catch syntax errors early with a clear message.
  • Specific \SyntaxError\ handling on \io_handler.parse(): If rendering raises a \SyntaxError, we now surface the exact error message and line number without leaking provider config details.
  • Specific \SyntaxError\ handling on \eval(): If the rendered code fails to evaluate with a \SyntaxError, we show the error with line number and a short preview of the rendered code (capped at 200 chars) for context.

Example of the improved error (after this fix):
\
SyntaxError in Python step 'my-python-step': invalid syntax (line 3)
\\

Testing

Manual verification that:

  • Valid Python expressions continue to work correctly
  • Syntax errors in user code now produce clear, actionable error messages
  • Provider config data is no longer leaked in error messages

@DragonBot00
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

@DragonBot00 is attempting to deploy a commit to the KeepHQ Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 1, 2026
@TheCodingDragon0
Copy link
Copy Markdown

Closing — no maintainer engagement after 5 days. Shifting focus to quality over quantity.

1 similar comment
@DragonBot00
Copy link
Copy Markdown
Contributor Author

Closing — no maintainer engagement after 5 days. Shifting focus to quality over quantity.

@DragonBot00 DragonBot00 closed this Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Unclear error for python step execution

2 participants