N/llm generateText Now Supports Tool Calling, Structured Output, and Safety Modes
The N/llm module's generateText method gains tool-calling support in 2025.2 (options.tools, options.toolResults), adding to structured JSON output (options.responseFormat), document RAG (options.documents), and safety modes introduced in 2025.1. The method costs 100 governance units per call and runs server-side only.
The llm.generateText(options) method — aliased as llm.chat(options) — is the primary entry point for calling LLMs from SuiteScript 2.1 via the N/llm module. Originally shipped in 2024.1, it has been progressively expanded. Here is a consolidated breakdown of the API surface through 2025.2, with emphasis on the newest capabilities.
What changed in 2025.2: Tool Calling
Two new parameters enable agentic tool-use patterns:
options.tools(llm.Tool[]) — Declares tools (functions) the LLM may request during generation. When the model decides it needs external data, the response object'sResponse.toolCallsproperty contains the requested invocations.options.toolResults(llm.ToolResult[]) — Feeds completed tool results back intogenerateTextso the LLM can produce a follow-up response incorporating those results. WhentoolResultsis specified, any value inoptions.promptis ignored.
This creates a two-call loop: call generateText with tools → inspect response.toolCalls → execute the requested tools in your script → call generateText again with toolResults. Each call costs 100 governance units, so a single tool-augmented exchange burns at least 200 units.
What changed in 2025.1
options.documents(llm.Document[]) — Supplies documents for retrieval-augmented generation (RAG). Cohere models only. Create documents viallm.createDocument(options). Document IDs must be unique or you getDOCUMENT_IDS_MUST_BE_UNIQUE.options.responseFormat(JSON Schema object) — Forces the LLM to return structured JSON matching your schema. Parse the result withJSON.parse(response.text). Cohere models only. Cannot be combined withoptions.documents,options.tools, oroptions.toolResults(throwsMUTUALLY_EXCLUSIVE_ARGUMENTS).options.safetyMode— Controls content filtering via thellm.SafetyModeenum. Defaults tollm.SafetyMode.STRICT. Even withllm.SafetyMode.OFF, some content filtering is still enforced and can throwINAPPROPRIATE_CONTENT_DETECTED.
Existing parameters (2024.1–2024.2)
options.prompt(string) — Required unlesstoolResultsis provided.options.chatHistory(llm.ChatMessage[]) — Prior conversation turns for multi-turn chat.options.preamble(string) — System-level instruction/context. Not all models accept it (MODEL_1_DOES_NOT_ACCEPT_PREAMBLE).options.modelFamily(string, since 2024.2) — Select the LLM viallm.ModelFamilyenum. Defaults to Cohere Command A (cohere.command-a-03-2025).options.modelParameters—maxTokens,temperature,topK,topP,frequencyPenalty,presencePenalty. Note: forCOHERE_COMMAND, you cannot set bothfrequencyPenaltyandpresencePenaltyabove zero simultaneously.options.ociConfig— Needed only for unlimited-usage mode via your own OCI Generative AI service account. AcceptsuserId,tenancyId,compartmentId,fingerprint,privateKey. ThefingerprintandprivateKeyvalues must be NetSuite API secrets (not raw strings) or you getONLY_API_SECRET_IS_ACCEPTED. OCI config can also be set globally on the AI Preferences > SuiteScript subtab; per-call values override the global config.options.timeout— Defaults to 30,000 ms.
Runtime constraints
- Governance: 100 units per call.
- Script type: Server-side scripts only.
- Parallelism: Maximum 5 concurrent LLM requests per script execution (
MAXIMUM_PARALLEL_REQUESTS_LIMIT_EXCEEDED).
Key error codes to handle
SSS_MISSING_REQD_ARGUMENT— No prompt and no toolResults.MUTUALLY_EXCLUSIVE_ARGUMENTS—responseFormatcombined withdocuments,tools, ortoolResults; or both penalty parameters set for Cohere Command.INAPPROPRIATE_CONTENT_DETECTED— Safety filter triggered (even with safety mode off).INVALID_*_VALUEfamily — Model parameter out of range; check Model Parameter Values by LLM in the NetSuite help.
What to do
- If you are already using
N/llm— Review the newoptions.toolsandoptions.toolResultsparameters. Tool calling lets your SuiteScript act as an agent orchestrator, but remember each round-trip is 100 governance units. Plan your governance budget accordingly, especially in scheduled or map/reduce scripts. - If you want structured output — Use
options.responseFormatwith a JSON schema instead of hoping the prompt returns parseable JSON. This is Cohere-only and cannot be used alongsidetools,toolResults, ordocuments. - If you use unlimited-usage (BYO OCI) mode — Prefer setting OCI config on the AI Preferences > SuiteScript subtab for account-wide defaults. Use per-call
ociConfigonly when you need to override for a specific script. EnsurefingerprintandprivateKeyare stored as NetSuite Secrets (Setup > Company > API Secrets), not hardcoded strings. - Governance planning — A tool-calling exchange is at minimum 2 × 100 = 200 units. With a 5-request parallelism cap, batch designs that fan out many LLM calls need serialization or chunking. Factor this into your script-type selection (Scheduled, Map/Reduce, RESTlet).
- Default model awareness — The default
modelFamilyis now Cohere Command A (cohere.command-a-03-2025). If your code relied on a previous default, explicitly setoptions.modelFamilyto maintain consistent behavior.
Source: Oracle NetSuite Release Notes