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:

  • return outside a nested def, and yield anywhere;
  • calls to print(...) (including builtins.print(...)) anywhere; use workflows.log(...) to emit output instead;
  • unterminated strings, unbalanced brackets, and inconsistent indentation, reported as workflow syntax error.

Imports, while loops, and private names are allowed.

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) {
    _checkPrintCalls(line);
  }
}