N/llm Module: createToolResult Method for Tool-Use Round-Trips
SuiteScript 2.1 gains llm.createToolResult() in the N/llm module, enabling scripts to return structured tool outputs back to the LLM within a multi-turn generate-text flow.
What changed
The N/llm module now exposes llm.createToolResult(options), completing the tool-use loop introduced alongside llm.generateText() and llm.generateTextStreamed() in 2025.2. When the LLM responds with a llm.ToolCall object (asking your script to execute an action such as a SuiteQL query or a record operation), you handle that action in your own code, then wrap the output in a llm.ToolResult and feed it back into the next generateText or generateTextStreamed call. The LLM incorporates those results to produce a more accurate final response.
Method signature
- Module:
N/llm - Method:
llm.createToolResult(options) - Returns:
llm.ToolResult - Governance: None
- Script types: Server scripts only (Scheduled, Map/Reduce, Suitelet, User Event, RESTlet, etc.)
Parameters
options.call(llm.ToolCall, required) — The original tool-call request object returned by the LLM. This links the result back to the specific call.options.outputs(Object[], required) — An array of output objects. Each object should include aresultproperty (or equivalent) containing the value to return to the LLM.
Typical flow
- Define tools and call
llm.generateText()orllm.generateTextStreamed(). - Inspect the response for
llm.ToolCallobjects. - Execute the requested operation (e.g., run a
N/querySuiteQL query, create or load a record viaN/record). - Call
llm.createToolResult({ call: toolCall, outputs: [{ result: handlerResult }] }). - Pass the
ToolResultinto a subsequentgenerateText/generateTextStreamedcall so the LLM can incorporate it.
Example (non-functional, per Oracle docs)
const toolResult = llm.createToolResult({
call: toolCall,
outputs: [{ result: handlerResult }]
});
What to do
- Review your existing N/llm integrations. If you are already calling
llm.generateText()with tool definitions but were manually re-prompting the model with stringified results, switch to the formalcreateToolResultpath for cleaner round-trips. - Structure outputs carefully. The
outputsarray accepts multiple objects — useful when a single tool call produces several discrete results. Each object should carry aresultproperty with the data the LLM needs. - No governance cost.
createToolResultitself consumes zero governance units. Governance is incurred only on the subsequentgenerateText/generateTextStreamedcall that processes the result, so plan unit budgets around those calls, not this one. - Server scripts only. This method is unavailable in client scripts. If you need LLM tool-use from the browser, route through a Suitelet or RESTlet.
- Consult the full samples. Oracle references N/llm Module Script Samples for a complete working example — review those for end-to-end patterns including error handling on tool execution failures.
Source: Oracle NetSuite Release Notes