Skip to main content
Question

Python functions are failing to return values; No error reported from action

  • March 3, 2026
  • 4 replies
  • 16 views

Forum|alt.badge.img+7

I cannot figure out what is going wrong here.

I have a python script which is supposed to return a string value to my task.

The basic function returns like this, which combines numbers into a pipe delimited string using f-strings.

return f"{total}|{success}|{validation}|{error}"

When I run this bot in debug, it works fine.

When I deploy this, the function doesn’t fail, but the returned string is “null” instead.

“Python output for get_status_counts: null”

 

If I modify my script to write this string to a file, it writes what I would expect.

 

Multiple different bots are having this error. I tried updating packages but it doesn’t seem to have any impact.

 

Part of the log from when this runs:

2026-Mar-03 Tue 11:50:14.756 DEBUG [BotRunner-570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd] - com.automationanywhere.python.commands.ExecuteFunction {deploymentId=570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd, traceId=3e4c19e21d7454cd} - execute(ExecuteFunction.java:105) - session: com.automationanywhere.python.utility.PythonSession@1666ad38, callFunction: b977ce0b-bd6c-4262-a8e3-6fabfbd8f1b5, input:{"functionName":"get_status_counts","arguments":[],"filePath":"C:\\Users\\BotUser01\\AppData\\Local\\AA\\resources\\570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd\\b977ce0b-bd6c-4262-a8e3-6fabfbd8f1b5\\bot.py"}
2026-Mar-03 Tue 11:50:14.756 INFO [BotRunner-570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd] - com.automationanywhere.sdk.python.functions.ExternalEnvironmentImpl {deploymentId=570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd, traceId=3e4c19e21d7454cd} - callFunction(ExternalEnvironmentImpl.java:114) - python-sdk-Calling external function b977ce0b-bd6c-4262-a8e3-6fabfbd8f1b5
2026-Mar-03 Tue 11:50:14.756 INFO [BotRunner-570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd] - com.automationanywhere.sdk.python.functions.ExternalFunctionImpl {deploymentId=570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd, traceId=3e4c19e21d7454cd} - callFunction(ExternalFunctionImpl.java:61) - python-sdk-Passing input to function b977ce0b-bd6c-4262-a8e3-6fabfbd8f1b5 for process:19336
2026-Mar-03 Tue 11:50:14.756 INFO [BotRunner-570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd] - com.automationanywhere.sdk.python.functions.ExternalFunctionImpl {deploymentId=570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd, traceId=3e4c19e21d7454cd} - callFunction(ExternalFunctionImpl.java:73) - python-sdk-Received output from function b977ce0b-bd6c-4262-a8e3-6fabfbd8f1b5 for process:19336
2026-Mar-03 Tue 11:50:14.757 INFO [Thread-13] - ExternalScript {deploymentId=570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd, traceId=3e4c19e21d7454cd} - log_aroundBody0(LogUtil.java:32) - 2026-03-03 11:50:14,756 - root - DEBUG - msg: {"functionName":"get_status_counts","arguments":[],"filePath":"C:\\Users\\BotUser01\\AppData\\Local\\AA\\resources\\570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd\\b977ce0b-bd6c-4262-a8e3-6fabfbd8f1b5\\bot.py"}
2026-Mar-03 Tue 11:50:14.757 INFO [Thread-13] - ExternalScript {deploymentId=570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd, traceId=3e4c19e21d7454cd} - log_aroundBody0(LogUtil.java:32) - 2026-03-03 11:50:14,757 - root - INFO - importing bot for execution..
2026-Mar-03 Tue 11:50:14.757 DEBUG [BotRunner-570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd] - com.automationanywhere.python.commands.ExecuteFunction {deploymentId=570644a3-2854-43c5-a058-7a6d59646bb9_3e4c19e21d7454cd, traceId=3e4c19e21d7454cd} - execute(ExecuteFunction.java:116) - session: com.automationanywhere.python.utility.PythonSession@1666ad38, callFunction returned: null

Anyone have any ideas?

4 replies

Forum|alt.badge.img
  • Cadet | Tier 2
  • March 3, 2026

Hi,

You’re probably not hitting a Python issue but how Automation Anywhere captures the output.

In external Python mode, the platform often relies on stdout, not just return. That’s why it works in debug but comes back as null when deployed.

try this one: 

result = f"{total}|{success}|{validation}|{error}"

print(result)

return result

 

If that fixes it, then it confirms AA wasn’t reading the return properly.

 


Forum|alt.badge.img+7
  • Author
  • Navigator | Tier 3
  • March 3, 2026

try this one: 

result = f"{total}|{success}|{validation}|{error}"

print(result)

return result

My example used to work just fine until last Friday from what I can tell.

That said, I did try modifying the output like you show and it is still returning “null” in my production bot.


Aaron.Gleason
Automation Anywhere Team
Forum|alt.badge.img+14
  • Automation Anywhere Team
  • March 3, 2026

@sleemand Try defining a function and calling it that way.

def myGreatFunction(inputValue):
return inputValue

Make sure this works first and then build upon it. Defining a function gives you a lot more flexibility than calling the Python script directly.  


Forum|alt.badge.img+7
  • Author
  • Navigator | Tier 3
  • March 3, 2026

@sleemand Try defining a function and calling it that way.

def myGreatFunction(inputValue):
return inputValue

Make sure this works first and then build upon it. Defining a function gives you a lot more flexibility than calling the Python script directly.  

@Aaron.Gleason 

Sorry if I wasn’t clear in the post, but that is exactly how I’m doing it.

This used to work for the last 6+ months until I saw it failing on Friday (2-27-26) and now it is failing for all scripts that are returning values.

 

Here is my task steps and the debug run:

Here is the full code, but it relies on the way I’m printing to the log file for my document automation statuses in order to work right.


import re

DA_VALIDATION_LINE = 'DW_EXTRACT_VALIDATION'
DA_PO_VALIDATION_LINE = 'DW_PO_VALIDATION'
DA_PO_ERROR_LINE = 'Loop number 10 failed'

ID_PATTERN = r'((APINV|LINDE)-\d+)'
ID_PATTERN = re.compile(ID_PATTERN)

def read_log(in_file):
with open(in_file, 'r') as f:
lines = f.read().strip().split('\n')
return lines

def get_request_status(request_id, lines, ref_dic):
request_lines = [l for l in lines if request_id in l]
validation = not [l for l in request_lines if DA_VALIDATION_LINE in l] == []
po_validation = not [l for l in request_lines if DA_PO_VALIDATION_LINE in l] == []
po_validation_error = not [l for l in request_lines if DA_PO_ERROR_LINE in l] == []
success = validation == po_validation == po_validation_error == False
status = 'UNKNOWN'
if validation or po_validation:
status = 'VALIDATION'
ref_dic['validation'] = 1
if success:
status = 'SUCCESS'
ref_dic['success'] = 1
if po_validation_error:
status = 'ERROR'
ref_dic['error'] = 1
ref_dic['validation'] = 0
ref_dic['success'] = 0
return status

def get_request_ids(lines):
req_refs = []
created_lines = [l for l in lines if 'created for' in l]
for l in created_lines:
req_ref = {}
m = re.search(ID_PATTERN,l)
key = m[0] if m else None
req_ref['key'] = key
req_ref['success'] = 0
req_ref['validation'] = 0
req_ref['error'] = 0
req_ref['status'] = get_request_status(key, lines, req_ref)
req_refs.append(req_ref)
return req_refs

def get_validation_ref_ids():
validation_pending = [r['key'] for r in ref if r['validation']]
return '|'.join(validation_pending)

def get_success_ids():
success = [r['key'] for r in ref if r['success']]
return '|'.join(success)

def get_status_counts():
success = len([r for r in ref if r['success']])
validation = len([r for r in ref if r['validation']])
error = len([r for r in ref if r['error']])
total = len(ref)
output = f"{total}|{success}|{validation}|{error}"
print(output)
return output

def main(in_file):
global ref
lines = read_log(in_file)
ref = get_request_ids(lines)


if __name__ == '__main__':
in_file = r'\\SHGHAPP12\Users\BotUser01\Documents\Automation Anywhere Files\Automation Anywhere\My Docs\AP_Processing\Logs\BotRunLogs\Logs_01082026_001512.txt'
main(in_file)
aa_out = get_validation_ref_ids()
aa_counts = get_status_counts()
print(aa_out)

I also have simpler scripts/functions that are behaving the same way.

from datetime import datetime
d = {}
def import_email_file(in_file):
global d
d = {}
with open(in_file, 'r', encoding='utf-8') as f:
c = f.read().strip().split('\n')
for r in c:
date, fullpath = r.split(',')
parsed_date = datetime.strptime(date,'%d/%m/%Y %H:%M:%S')
string_date = parsed_date.strftime('%d-%b-%y')
filekey = fullpath.split('\\')[-1].split('.')[0]
d[filekey] = '|'.join([string_date, fullpath])

def get_email_details(key):
return d.get(key,'Not Found')

if __name__ == '__main__':
in_file = r"\\shghapp12\Users\BotUser01\Documents\Automation Anywhere Files\Automation Anywhere\My Docs\AP_Processing\BatchCodes\EmailDetail.csv"
import_email_file(in_file)
key = '03022026_001648_Linde_InputFile_190'
details = get_email_details(key)
print(details)