import ast def validate_ast(code): try: ast.parse(code) return True, None except SyntaxError as e: return False, f"{e.msg} (line {e.lineno})"