AI Agents tools - script tool output setting

stevenatwork
Tera Expert

Hi Everyone,

 

I’m building a Gen AI Agent in ServiceNow that uses a Script Tool to extract and return values like extracted_text.  The tool executes successfully, and I see a proper return from the script like this:

return { "extracted_text": textContent };

However, in the Agent Execution Logs, the output is coming through as empty
{"extracted_text":{}}

What I've Checked:

  • The Script runs successfully and returns the expected object.

  • The Display Output checkbox is enabled on the tool.

  • My tool is linked via Agent Tool [sn_aia_agent_tool_m2m] to the skill.

  • I'm working in the global scope.

  • The field Tool Outputs is also not visible to manually define the output keys.

 

My Main Question:

How are other out-of-box AI Agent tools able to populate outputs, and can I manually define Tool Outputs for a custom Script Tool?

Do I need to:

  • Activate a plugin?

  • Switch to a specific scope?

  • Add related lists manually?

  • Or anything else
1 ACCEPTED SOLUTION

I was able to identify the issue. Although the script executed successfully, it was returning text that contained special characters (such as newlines and carriage returns), which caused the return statement to fail. I resolved this by using JavaScript regular expressions to replace the special characters, and it worked as expected.

Thank you.

View solution in original post

2 REPLIES 2

anubhavkapoor76
ServiceNow Employee
ServiceNow Employee

@stevenatwork - It would be helpful if you add few screenshots to this post.

 

I was able to identify the issue. Although the script executed successfully, it was returning text that contained special characters (such as newlines and carriage returns), which caused the return statement to fail. I resolved this by using JavaScript regular expressions to replace the special characters, and it worked as expected.

Thank you.