LLMGraph
Details and Options
- An LLMGraph can be used to efficiently schedule and combine multiple LLM generation steps for an optimal evaluation managing LLM submissions' concurrency.
- LLMGraph requires external service authentication, billing and internet connectivity.
- Possible values for the node function funi include:
-
LLMFunction[…] an LLMFunction for LLM submission Function[…] a pure function for Wolfram kernel submission <|key1val1, …|> an Association with detailed node specifications nodespec - Possible node specifications keys in nodespec are:
-
"EvaluationFunction" arbitrary Wolfram Language Function "LLMFunction" LLM evaluation via an LLMFunction "ListableLLMFunction" threaded LLM evaluation on list input values "Input" explicit list of nodes required as function arguments "TestFunction" whether the node should run "TestFunctionInput" explicit list of nodes required as test arguments - Each node must be defined with only one of "EvaluationFunction", "LLMFunction" or "ListableLLMFunction".
- The function specified in "ListableLLMFunction" threads over list input. Non-list input is copied. The output of the node is always a list.
- The "TestFunction" specification makes a node evaluation conditional on other nodes' results.
- Possible "LLMFunction" specifications prompti include:
-
"text" static text {"text1",…} a list of strings LLMPrompt["name"] a repository prompt StringTemplate[…] templated text TemplateObject[…] template for creating a prompt LLMFunction[…] an LLMFunction object - If a prompti is explicitly dependent on the parameter TemplateSlot["namej"], the result from the nodej evaluation will be computed first, then used to build the new prompt.
- Cyclic prompt dependencies are not supported.
- The syntax LLMGraph[…][input] is used to run a graph evaluation.
- Any nodei result can be provided in input. Possible values for input are:
-
val value for the single graph input <|name1val1, …|> values for each of the nodes or inputs namei - Explicitly provided vali will be used in place of the node function result.
- The computation in a node is started as soon as all its dependencies are available.
- The syntax LLMGraph[…][input,prop] returns specific properties.
- Possible values for prop are:
-
Automatic results for the output nodes All results for all the nodes "LLMGraph" a new LLMGraph annotated with the result - LLMGraph supports the following options:
-
Authentication Automatic fallback authentication LLMEvaluator $LLMEvaluator fallback LLM configuration ProgressReporting $ProgressReporting whether to report the progress of the computation - To evaluate a node, its own LLMConfiguration nconf will be used. LLMEvaluatorgconf can be used to specify defaults for Missing[…] or Automatic values.
Examples
open all close allBasic Examples (2)
bestpoem = LLMGraph[<|
"Poet1" -> "write a short poem about summer",
"Poet2" -> "write a haiku about winter",
"Judge" -> "Choose the best composition of your among these:
1) Poem1: `Poet1`
2) Poem2: `Poet2`
and copy it:"
|>]bestpoem[]Define a basic graph taking an evaluation input:
renga = LLMGraph[<|
"haiku" -> "generate a haiku about `Topic`.",
"complete" -> "add an extra stanza to the hokku `haiku` to make it a renga."
|>]Evaluate the graph, providing a topic:
renga[<|"Topic" -> "spring"|>]Return all the nodes evaluation results:
renga[<|"Topic" -> "autumn"|>, All]Return an LLMGraph including computation results:
renga[<|"Topic" -> "autumn"|>, "LLMGraph"]Scope (23)
Node Specification (9)
LLMFunction (4)
Specify an LLM node and its connections using an Association:
LLMGraph[<|"LLMSubmission" -> <|"LLMFunction" -> LLMFunction["what is `Argument`?"], "Input" -> {"Argument"} |>|>]Specify the node using LLMFunction and relying on the automatic dependencies resolution:
LLMGraph[<|"LLMSubmission" -> LLMFunction["what is `Argument`?"]|>]Specify the node using a template:
LLMGraph[<|"LLMSubmission" -> StringTemplate["what is `Argument`?"]|>]Use any valid LLMFunction prompt specification:
LLMGraph[<|"LLMSubmission" -> "what is `Argument`?"|>]ListableLLMFunction (1)
Define a "ListableLLMFunction" to thread over its input elements:
parallel = LLMGraph[<|
"NameMap" -> <|"ListableLLMFunction" -> LLMFunction["Write `Elements` in full letters:
"]|>
|>]Evaluate the graph with LLM generation submitted concurrently:
parallel[{"1", "2", "3"}]Compare with the "LLMFunction" behavior; a single LLM generation is submitted with the entire list, returning a single output:
LLMGraph[<|
"NameMap" -> <|"LLMFunction" -> LLMFunction["Write `Elements` in full letters:
"]|>
|>][{"1", "2", "3"}]EvaluationFunction (2)
Specify arbitrary Wolfram Language code in the node using an "EvaluationFunction":
LLMGraph[<|"WolframCode" -> <|"EvaluationFunction" -> Function[2 * #["Argument"]], "Input" -> {"Argument"} |>|>]Use a pure Function with named Slot and rely on the automatic dependencies resolution:
LLMGraph[<|"WolframCode" -> Function[2 * #Argument]|>]Conditional Evaluation (2)
Specify an arbitrary test function to condition the node evaluation:
conditioned = LLMGraph[<|"ConditionalNode" -> <|"EvaluationFunction" -> Function[Success["NodeHasRun", <||>]], "TestFunction" -> Function[TrueQ[#NodeControl]],
"InputTestFunction" -> {"NodeControl"}
|>|>]The node function is run only if "TestFunction" result is True:
conditioned[<|"NodeControl" -> True|>]Skipped node returns a Missing[…] object:
conditioned[<|"NodeControl" -> False|>]Rely on the automatic dependencies resolution for "TestFunction":
conditioned = LLMGraph[<|"ConditionalNode" -> <|"EvaluationFunction" -> Function[Success["NodeHasRun", <||>]], "TestFunction" -> Function[TrueQ[#NodeControl]]
|>|>]Evaluation (9)
Node Initialization (4)
Provide input nodes' values to start the graph evaluation:
LLMGraph[Association["Nodes" -> Association["Arg1" -> Association["Name" -> "Arg1",
"PendingDependencies" -> {}], "Arg2" -> Association["Name" -> "Arg2",
"PendingDependencies" -> {}], "OutputNode1" -> Association["Input" -> {"Arg1"}, ... c, "TotalProbabilityCutoff" -> Automatic, "Prompts" -> Automatic,
"PromptDelimiter" -> "\n\n", "StopTokens" -> Automatic, "ToolMethod" -> "Service",
"Tools" -> Automatic, "LLMPacletVersion" -> "2.2.3"]], "LLMPacletVersion" -> "2.2.3"]][<|"Arg1" -> 1, "Arg2" -> 2|>]If a single input is required, it is not necessary to use the Association:
LLMGraph[Association["Nodes" -> Association["Arg1" -> Association["Name" -> "Arg1",
"PendingDependencies" -> {}], "MiddleNode" -> Association["Input" -> {"Arg1"},
"EvaluationFunction" -> ("intermediate result" & ), "Name" -> "MiddleNo ... tomatic, "Prompts" -> Automatic,
"PromptDelimiter" -> Automatic, "StopTokens" -> Automatic, "ToolMethod" -> Automatic,
"Tools" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic,
"LLMPacletVersion" -> "2.3"]][1]LLMGraph[Association["Nodes" -> Association["Arg1" -> Association["Name" -> "Arg1",
"PendingDependencies" -> {}], "MiddleNode" -> Association["Input" -> {"Arg1"},
"EvaluationFunction" -> ("intermediate result" & ), "Name" -> "MiddleNo ... tomatic, "Prompts" -> Automatic,
"PromptDelimiter" -> Automatic, "StopTokens" -> Automatic, "ToolMethod" -> Automatic,
"Tools" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic,
"LLMPacletVersion" -> "2.3"]][<|"Arg1" -> 1|>]If no input is required, the graph can be evaluated on an empty sequence:
LLMGraph[Association["Nodes" -> Association["OutputNode1" -> Association["Input" -> {},
"EvaluationFunction" -> ("Output node 1 result" & ), "Name" -> "OutputNode1",
"PendingDependencies" -> {}], "MiddleNode" -> Association["Input" -> ... tomatic, "Prompts" -> Automatic,
"PromptDelimiter" -> Automatic, "StopTokens" -> Automatic, "ToolMethod" -> Automatic,
"Tools" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic,
"LLMPacletVersion" -> "2.3"]][]LLMGraph[Association["Nodes" -> Association["OutputNode1" -> Association["Input" -> {},
"EvaluationFunction" -> ("Output node 1 result" & ), "Name" -> "OutputNode1",
"PendingDependencies" -> {}], "MiddleNode" -> Association["Input" -> ... tomatic, "Prompts" -> Automatic,
"PromptDelimiter" -> Automatic, "StopTokens" -> Automatic, "ToolMethod" -> Automatic,
"Tools" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic,
"LLMPacletVersion" -> "2.3"]][<||>]Providing a result for the intermediate nodes will bypass the node function evaluation:
LLMGraph[Association["Nodes" -> Association["Arg1" -> Association["Name" -> "Arg1",
"PendingDependencies" -> {}], "Arg2" -> Association["Name" -> "Arg2",
"PendingDependencies" -> {}], "OutputNode1" -> Association["Input" -> {"Arg1"}, ... tomatic, "Prompts" -> Automatic,
"PromptDelimiter" -> Automatic, "StopTokens" -> Automatic, "ToolMethod" -> Automatic,
"Tools" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic,
"LLMPacletVersion" -> "2.3"]][<|"OutputNode1" -> "custom result", "Arg2" -> 2|>]Evaluation Properties (5)
Evaluate output nodes' result of an LLMGraph; they are returned in an Association:
LLMGraph[Association["Nodes" -> Association["Arg1" -> Association["Name" -> "Arg1",
"PendingDependencies" -> {}], "Arg2" -> Association["Name" -> "Arg2",
"PendingDependencies" -> {}], "OutputNode1" ->
Association["EvaluationFunc ... tomatic, "Prompts" -> Automatic,
"PromptDelimiter" -> Automatic, "StopTokens" -> Automatic, "ToolMethod" -> Automatic,
"Tools" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic,
"LLMPacletVersion" -> "2.3"]][<|"Arg1" -> 1, "Arg2" -> 2|>]Evaluate a single output node LLMGraph result; it is returned unwrapped:
LLMGraph[Association["Nodes" -> Association["Arg1" -> Association["Name" -> "Arg1",
"PendingDependencies" -> {}], "Arg2" -> Association["Name" -> "Arg2",
"PendingDependencies" -> {}], "OutputNode1" -> Association["Input" -> {"Arg1", " ... tomatic, "Prompts" -> Automatic,
"PromptDelimiter" -> Automatic, "StopTokens" -> Automatic, "ToolMethod" -> Automatic,
"Tools" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic,
"LLMPacletVersion" -> "2.3"]][<|"Arg1" -> 1, "Arg2" -> 2|>]Request all nodes' results from an LLMGraph evaluation, including input and intermediate nodes:
LLMGraph[Association["Nodes" -> Association["Arg1" -> Association["Name" -> "Arg1",
"PendingDependencies" -> {}], "Arg2" -> Association["Name" -> "Arg2",
"PendingDependencies" -> {}], "OutputNode1" ->
Association["EvaluationFunc ... tomatic, "Prompts" -> Automatic,
"PromptDelimiter" -> Automatic, "StopTokens" -> Automatic, "ToolMethod" -> Automatic,
"Tools" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic,
"LLMPacletVersion" -> "2.3"]][<|"Arg1" -> 1, "Arg2" -> 2|>, All]Request an updated LLMGraph including the computation results:
LLMGraph[Association["Nodes" -> Association["Arg1" -> Association["Name" -> "Arg1",
"PendingDependencies" -> {}], "Arg2" -> Association["Name" -> "Arg2",
"PendingDependencies" -> {}], "OutputNode1" ->
Association["EvaluationFunc ... tomatic, "Prompts" -> Automatic,
"PromptDelimiter" -> Automatic, "StopTokens" -> Automatic, "ToolMethod" -> Automatic,
"Tools" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic,
"LLMPacletVersion" -> "2.3"]][<|"Arg1" -> 1, "Arg2" -> 2|>, "LLMGraph"]Request a partially updated LLMGraph; when some dependencies are not satisfied by node initialization, only a subset of the nodes is assigned a result:
LLMGraph[Association["Nodes" -> Association["Arg1" -> Association["Name" -> "Arg1",
"PendingDependencies" -> {}], "Arg2" -> Association["Name" -> "Arg2",
"PendingDependencies" -> {}], "OutputNode1" ->
Association["EvaluationFunc ... tomatic, "Prompts" -> Automatic,
"PromptDelimiter" -> Automatic, "StopTokens" -> Automatic, "ToolMethod" -> Automatic,
"Tools" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic,
"LLMPacletVersion" -> "2.3"]][<|"Arg1" -> 1|>, "LLMGraph"]Information (5)
Extract information from an LLMGraph:
Information[LLMGraph[Association["Nodes" -> Association[
"Poet2" -> Association["LLMFunction" -> TemplateObject[{"write a haiku about winter"},
CombinerFunction -> StringJoin, InsertionFunction -> TextString,
MetaInformation -> Associatio ... Automatic, "Prompts" -> Automatic, "PromptDelimiter" -> Automatic,
"StopTokens" -> Automatic, "ToolMethod" -> Automatic, "Tools" -> Automatic,
"LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic, "LLMPacletVersion" -> "2.3"]]]Get a list of the supported properties:
Information[LLMGraph[Association["Nodes" -> Association[
"Poet2" -> Association["LLMFunction" -> TemplateObject[{"write a haiku about winter"},
CombinerFunction -> StringJoin, InsertionFunction -> TextString,
MetaInformation -> Associatio ... Automatic, "Prompts" -> Automatic, "PromptDelimiter" -> Automatic,
"StopTokens" -> Automatic, "ToolMethod" -> Automatic, "Tools" -> Automatic,
"LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Properties"]Get the evaluation workflow as a Graph:
Information[LLMGraph[Association["Nodes" -> Association[
"Poet2" -> Association["LLMFunction" -> TemplateObject[{"write a haiku about winter"},
CombinerFunction -> StringJoin, InsertionFunction -> TextString,
MetaInformation -> Associatio ... Automatic, "Prompts" -> Automatic, "PromptDelimiter" -> Automatic,
"StopTokens" -> Automatic, "ToolMethod" -> Automatic, "Tools" -> Automatic,
"LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Graph"]Get information about the nodes' contents, including potential evaluation results, formatted as a Dataset:
Information[LLMGraph[Association["Nodes" -> Association[
"Poet2" -> Association["LLMFunction" -> TemplateObject[{"write a haiku about winter"},
CombinerFunction -> StringJoin, InsertionFunction -> TextString,
MetaInformation -> Associatio ... Automatic, "Prompts" -> Automatic, "PromptDelimiter" -> Automatic,
"StopTokens" -> Automatic, "ToolMethod" -> Automatic, "Tools" -> Automatic,
"LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Nodes"]Get an evaluated nodes' results LLMGraph:
Information[LLMGraph[Association["Nodes" -> Association[
"Poet2" -> Association["LLMFunction" -> TemplateObject[{"write a haiku about winter"},
CombinerFunction -> StringJoin, InsertionFunction -> TextString,
MetaInformation -> Associatio ... Automatic, "Prompts" -> Automatic, "PromptDelimiter" -> Automatic,
"StopTokens" -> Automatic, "ToolMethod" -> Automatic, "Tools" -> Automatic,
"LLMPacletVersion" -> "2.3"]], "Authentication" -> Automatic, "LLMPacletVersion" -> "2.3"]], "Nodes"][[All, "Result"]]Options (6)
LLMEvaluator (2)
Define a graph default LLMConfiguration[…]:
graph = LLMGraph[<|"LLMCall1" -> "Hello Anthropic!", "LLMCall2" -> "Hello Anthropic!"|>, LLMEvaluator -> LLMConfiguration[<|"Model" -> {"Anthropic", Automatic}|>]
]Check the node LLMConfiguration[…]:
Map[ Information[#LLMFunction, "LLMEvaluator"]&]@Information[graph, "Nodes"]//NormalFully specify the node LLMFunction to define a node-specific LLMConfiguration[…]:
graph = LLMGraph[<|"LLMCall1" -> "Hello default service!", "LLMCall2" -> LLMFunction["Hello OpenAI!", LLMEvaluator -> LLMConfiguration[<|"Model" -> {"OpenAI", Automatic}|>]]|>
]The specific node LLMEvaluator is set:
Map[ Information[#LLMFunction, "LLMEvaluator"]&]@Information[graph, "Nodes"]//NormalAuthentication (4)
Provide an authentication key for the API:
LLMGraph[<|"LLMCall" -> "which element has atomic number 2?" |>, Authentication -> <|"APIKey" -> "1234abcd"|>, LLMEvaluator -> <|"Model" -> {"OpenAI", Automatic}|>]Look for the key in the system keychain:
LLMGraph[<|"LLMCall" -> "which element has atomic number 2?" |>, Authentication -> SystemCredential, LLMEvaluator -> <|"Model" -> {"OpenAI", Automatic}|>]LLMGraph[<|"LLMCall" -> "which element has atomic number 2?" |>, Authentication -> {SystemCredential, SystemCredentialKey -> "OPENAI_API_KEY"}, LLMEvaluator -> <|"Model" -> {"OpenAI", Automatic}|>]Look for the key in the system environment:
LLMGraph[<|"LLMCall" -> "which element has atomic number 2?" |>, Authentication -> Environment, LLMEvaluator -> <|"Model" -> {"OpenAI", Automatic}|>]Authenticate via a service object:
so = ServiceConnect["OpenAI"]LLMGraph[<|"LLMCall" -> "which element has atomic number 2?" |>, Authentication -> so]Applications (3)
Style Enforcement (1)
Combine LLM synthesis and deterministic Wolfram Language code in the graph:
poem = LLMGraph[<|
"Haiku" -> "write a haiku about `Topic`",
"Restyle" -> Function[ToUpperCase[#Haiku]]
|>]Inspect the computation graph to check input, output and dependencies resolution:
Information[poem, "Graph"]Submit the graph for evaluation. Single port graph input value is accepted directly:
poem["winter"]LLM-Based Review (1)
Define a step-by-step conditional correction flow using nodes with runtime evaluation tests:
CorrectWorkflow = LLMGraph[
<|
"Decide" -> "Decide if the following contains errors. Respond with either 'Correct' or 'Errors':
`Input`",
"Review" -> <|
"LLMFunction" -> "List any errors in the following:
`Input`",
"TestFunction" -> Function@StringContainsQ[#Decide, "Errors"]
|>,
"Rewrite" -> <|
"LLMFunction" -> "Rewrite \"Text\" to fix any issues specified in the \"Critique\":
=== Text ===
`Input`
=== Critique ===
`Review`
",
"TestFunction" -> Function@StringQ[#"Review"]
|>,
"Final" -> <|"EvaluationFunction" -> Function[If[StringQ[#Rewrite], "Incorrect input:
" <> #Input <> "
has been rewritten as:
" <> #Rewrite, #Input]], "Inputs" -> {"Rewrite", "Input"}|>
|>
]Inspect the automatic dependencies resolution:
Information[CorrectWorkflow, "Graph"]Run the correct input subgraph:
CorrectWorkflow["2 + 2 = 4"]Compare with the incorrect input one:
CorrectWorkflow["2 + 2 = 5"]Summarization (1)
Define a basic summarization workflow that accommodates the size-limited attention window of an LLM:
summarize = LLMGraph[
<|
"Chunk" -> <|"EvaluationFunction" -> Function @StringPartition[#Text, UpTo[12000]], "Input" -> {"Text"}|>,
"ChunkSummary" -> <|"ListableLLMFunction" -> "Summarize the following part in a few lines:
`Chunk`"|>,
"FinalSummary" -> "Summarize the following:
`ChunkSummary`"
|>
]Inspect the automatic dependencies resolution:
Information[summarize, "Graph"]Generate a summary of the US Constitution Preamble, submitting text chunks in parallel:
summarize[<|"Text" -> ExampleData[{"Text", "USConstitution"}]|>]Possible Issues (2)
Node function evaluations are run asynchronously. Side effects are directed to the Messages window:
LLMGraph[<|"SideEffect" -> Function[Echo[2 + 2]]|>][]A failed dependency will prevent the evaluation of a downstream node:
LLMGraph[<|"A" -> Function[$Failed], "B" -> Function[#A], "C" -> Function["good"]|>][]Individual node results can still be recovered from the evaluated LLMGraph:
LLMGraph[<|"A" -> Function[$Failed], "B" -> Function[#A], "C" -> Function["good"]|>][<||>, "LLMGraph"]Information[%, "Nodes"]Related Guides
History
Text
Wolfram Research (2025), LLMGraph, Wolfram Language function, https://reference.wolfram.com/language/ref/LLMGraph.html.
CMS
Wolfram Language. 2025. "LLMGraph." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/LLMGraph.html.
APA
Wolfram Language. (2025). LLMGraph. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LLMGraph.html
BibTeX
@misc{reference.wolfram_2026_llmgraph, author="Wolfram Research", title="{LLMGraph}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/LLMGraph.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_llmgraph, organization={Wolfram Research}, title={LLMGraph}, year={2025}, url={https://reference.wolfram.com/language/ref/LLMGraph.html}, note=[Accessed: 13-June-2026]}