validateWorkflowSource function

void validateWorkflowSource(
  1. String source
)

Validates Python workflow source against the run_workflow rules, so a disallowed script fails before the model is asked to run it.

Rejects, with a WorkflowException:

  • import and from ... import statements;
  • while loops (use bounded for loops);
  • attributes starting with _ and names starting with __;
  • return outside a nested def, and yield anywhere;
  • unterminated strings, unbalanced brackets, and inconsistent indentation, reported as workflow syntax error.

This is a lexical check, not a full Python parser: a script that passes may still contain syntax errors, which the harness reports when it runs the script. Expressions inside f-strings are not inspected.

Implementation

void validateWorkflowSource(String source) {
  final lines = _PythonLexer(source).logicalLines();
  _checkIndentation(lines);
  _checkReturnAndYield(lines);
  for (final line in lines) {
    _checkLine(line);
  }
}