-
See Also
- LLMExampleFunction
- LLMSynthesize
- LLMGraph
- LLMPrompt
- LLMTool
-
- Service Connections
- OpenAI
- Anthropic
- GoogleGemini
- Cohere
- DeepSeek
- Groq
- MistralAI
- TogetherAI
-
Related Guides
- Machine Learning
- Text Manipulation
- LLM-Related Functionality
- Text Analysis
- Natural Language Processing
- String Manipulation
- Working with Templates
- Converting between Expressions & Strings
- Linguistic Data
- Free-Form & External Input
- Setting Up Input Interpreters
- Knowledge Representation & Access
- Text Generation
- Text Normalization
-
-
See Also
- LLMExampleFunction
- LLMSynthesize
- LLMGraph
- LLMPrompt
- LLMTool
-
- Service Connections
- OpenAI
- Anthropic
- GoogleGemini
- Cohere
- DeepSeek
- Groq
- MistralAI
- TogetherAI
-
Related Guides
- Machine Learning
- Text Manipulation
- LLM-Related Functionality
- Text Analysis
- Natural Language Processing
- String Manipulation
- Working with Templates
- Converting between Expressions & Strings
- Linguistic Data
- Free-Form & External Input
- Setting Up Input Interpreters
- Knowledge Representation & Access
- Text Generation
- Text Normalization
-
See Also
LLMFunction[prompt]
represents a template for a large language model (LLM) prompt.
LLMFunction[{prompt1,prompt2,…}]
represents a combination of multiple prompts.
LLMFunction[prompt,form]
includes the interpreter form to apply to the response.
LLMFunction[…][params]
give the LLM service response for prompt applied to parameters params.
LLMFunction
LLMFunction[prompt]
represents a template for a large language model (LLM) prompt.
LLMFunction[{prompt1,prompt2,…}]
represents a combination of multiple prompts.
LLMFunction[prompt,form]
includes the interpreter form to apply to the response.
LLMFunction[…][params]
give the LLM service response for prompt applied to parameters params.
Details and Options
- An LLMFunction can be used to generate text using a large language model (LLM). It can create content, complete sentences, extract information and more.
- LLMFunction requires external service authentication, billing and internet connectivity.
- The prompti supports the following values:
-
"string" static string template LLMPrompt["name"] a repository prompt StringTemplate[…] templated text TemplateObject[…] template for creating a prompt {prompt1,…} a list of prompts - A prompt "string" is equivalent to StringTemplate["string"].
- Prompts created with TemplateObject can contain text and images. Not every LLM supports image input.
- The supported values of form are the same as Interpreter.
- When a form is specified, the LLM will be instructed to respect it.
- Specifying an output interpretation adds the corresponding schema information to the LLM prompt.
- LLMFunction supports the following options:
-
InsertionFunction TextString function or format to apply before inserting expressions CombinerFunction StringJoin function to apply to combine pieces within a prompt Authentication Automatic authentication scheme LLMEvaluator $LLMEvaluator LLM configuration to use - LLMEvaluator can be set to an LLMConfiguration object or an association with any of the following keys:
-
"MaxTokens" maximum amount of tokens to generate "Model" base model "PromptDelimiter" string to insert between prompts "Prompts" initial prompts "StopTokens" tokens on which to stop generation "Temperature" sampling temperature "ToolMethod" method to use for tool calling "Tools" list of LLMTool objects to make available "TopProbabilities" sampling classes cutoff "TotalProbabilityCutoff" sampling probability cutoff (nucleus sampling) - Valid forms of "Model" include:
-
name named model {service,name} named model from service <|"Service"service,"Name"name,"Task"task|> fully specified model - The generated text is sampled from a distribution. Details of the sampling can be specified using the following properties of LLMEvaluator:
-
"Temperature"t Automatic sample using a positive temperature t "TopProbabilities"k Automatic sample only among the k highest-probability classes "TotalProbabilityCutoff"p Automatic sample among the most probable choices with an accumulated probability of at least p (nucleus sampling) - Multiple prompts are separated by the "PromptDelimiter" property of the LLMEvaluator.
- Possible values for Authentication are:
-
Automatic choose the authentication scheme automatically Environment check for a key in the environment variables SystemCredential check for a key in the system keychain ServiceObject[…] inherit the authentication from a service object "string" provide an explicit API key - With AuthenticationAutomatic, the function checks the variable ToUpperCase[service]<>"_API_KEY" in Environment and SystemCredential; otherwise, it uses ServiceConnect[service].
- LLMFunction uses machine learning. Its methods, training sets and biases included therein may change and yield varied results in different versions of the Wolfram Language.
Examples
open all close allBasic Examples (3)
Create a function for getting cooking instructions:
LLMFunction["Describe how to cook `1`"]findbyproperty = LLMFunction["What is something that is `1` and `2`"]findbyproperty["Blue", "Round"]Create a function that returns a city as an Entity:
cityfinder = LLMFunction["Find a city between `1` and `2`. Answer with the city name only", "City"]cityfinder["St. Louis", "Chicago"]Scope (5)
Evaluate a function combining multiple prompts:
LLMFunction[{LLMPrompt["Yoda"], "What is something that is `1` and `2`", "answer in one sentence"}]["Blue", "Round"]teamfinder = LLMFunction["What team did `Pitcher` and `Catcher` play for?"]Apply it using an Association:
teamfinder[<|"Pitcher" -> "Whitey Ford", "Catcher" -> "Yogi Berra"|>]Set a default for a parameter:
recipe = LLMFunction[StringTemplate["Create a short recipe including `Veggie` annd `Spice`", <|"Spice" -> "Chili Powder"|>]]recipe[<|"Veggie" -> "Corn"|>]Use a multi-part prompt with images:
LLMFunction[TemplateObject@{"what is this?", TemplateSlot[1]}][[image]]Use an Interpreter to both constrain and validate the result:
f = LLMFunction["Generate `` random instances", RepeatingElement["Color"]]f[10]Options (6)
Authentication (4)
Provide an authentication key for the API:
SystemCredential["OPENAI_API_KEY"] = "<my-key>"Look for the key in the system keychain:
LLMFunction["the product of `1` and `2` is ", LLMEvaluator -> <|"Model" -> {"OpenAI", Automatic}|>, Authentication -> SystemCredential ]Store the API key in an environment variable:
SetEnvironment["OPENAI_API_KEY" -> "<my-key>"]Look for the key in the system environment:
LLMFunction["the product of `1` and `2` is ", LLMEvaluator -> <|"Model" -> {"OpenAI", Automatic}|>, Authentication -> Environment ]Authenticate via a service object:
so = ServiceConnect["OpenAI"]LLMFunction["the product of `1` and `2` is ", LLMEvaluator -> <|"Model" -> {"OpenAI", Automatic}|>, Authentication -> so]Provide an authentication key for the API:
LLMFunction["the product of `1` and `2` is ", LLMEvaluator -> <|"Model" -> {"OpenAI", Automatic}|>, Authentication -> "<my-key>" ]LLMEvaluator (2)
Specify the service and the model to use for the generation:
LLMFunction["Generate `` random color", LLMEvaluator -> <|"Model" -> {"Anthropic", Automatic}|>]Specify that the sampling should be performed at zero temperature:
fZero = LLMFunction["Generate a random `` color", "Color", LLMEvaluator -> <|"Temperature" -> 0|>]fZero /@ {"warm", "warm", "cool", "cool"}Specify a high temperature to get more variation in the generation:
fRandom = LLMFunction["Generate a random `` color", "Color", LLMEvaluator -> <|"Temperature" -> 1.5|>]fRandom /@ {"warm", "warm", "cool", "cool"}Properties & Relations (1)
LLMFunction with no parameters sends the prompt directly to the LLM:
LLMFunction["Hello"][]This is equivalent to LLMSynthesize with zero temperature:
LLMSynthesize["Hello", LLMEvaluator -> <|"Temperature" -> 0|>]See Also
LLMExampleFunction LLMSynthesize LLMGraph LLMPrompt LLMTool
Service Connections: OpenAI Anthropic GoogleGemini Cohere DeepSeek Groq MistralAI TogetherAI
Related Guides
-
▪
- Machine Learning ▪
- Text Manipulation ▪
- LLM-Related Functionality ▪
- Text Analysis ▪
- Natural Language Processing ▪
- String Manipulation ▪
- Working with Templates ▪
- Converting between Expressions & Strings ▪
- Linguistic Data ▪
- Free-Form & External Input ▪
- Setting Up Input Interpreters ▪
- Knowledge Representation & Access ▪
- Text Generation ▪
- Text Normalization
History
Introduced in 2023 (13.3) | Updated in 2025 (14.3)
Text
Wolfram Research (2023), LLMFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/LLMFunction.html (updated 2025).
CMS
Wolfram Language. 2023. "LLMFunction." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/LLMFunction.html.
APA
Wolfram Language. (2023). LLMFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LLMFunction.html
BibTeX
@misc{reference.wolfram_2026_llmfunction, author="Wolfram Research", title="{LLMFunction}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/LLMFunction.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_llmfunction, organization={Wolfram Research}, title={LLMFunction}, year={2025}, url={https://reference.wolfram.com/language/ref/LLMFunction.html}, note=[Accessed: 13-June-2026]}