micro/go-micro · error
LLM step requires a flow model (set Provider/APIKey)
Error message
LLM step requires a flow model (set Provider/APIKey)
What it means
The LLM step helper needs a configured language model on the flow's dependencies. Before executing the prompt it resolves the deps from the context; if there are no deps or the deps carry a nil model, the step fails immediately with this error. It exists so a missing model config surfaces as a clear message instead of a nil-pointer panic deep inside the model call.
Source
Thrown at flow/steps.go:315
return func(ctx context.Context, in State) (State, error) {
reply, err := a2a.NewClient(url).Send(ctx, in.String())
if err != nil {
return in, err
}
in.Data = []byte(reply)
return in, nil
}
}
// LLM returns a StepFunc that runs one augmented-LLM turn: it renders the
// prompt template against the current state (.Data, .Stage), lets the
// model call the flow's services as tools, and stores the reply as the
// new Data.
func LLM(prompt string) StepFunc {
return func(ctx context.Context, in State) (State, error) {
d := depsFrom(ctx)
if d == nil || d.model == nil {
return in, fmt.Errorf("LLM step requires a flow model (set Provider/APIKey)")
}
text := prompt
if tmpl, err := template.New("step").Parse(prompt); err == nil {
var buf bytes.Buffer
if tmpl.Execute(&buf, map[string]string{"Data": in.String(), "Stage": in.Stage}) == nil {
text = buf.String()
}
}
var tools []ai.Tool
if d.tools != nil {
tools, _ = d.tools.Discover()
}
resp, err := d.model.Generate(ctx, &ai.Request{Prompt: text, Tools: tools})
if err != nil {
return in, err
}
reply := resp.Answer
if reply == "" {View on GitHub (pinned to 24529f1404)
Solutions
- Configure the flow's model: pass Provider and APIKey options when constructing the flow so d.model is non-nil.
- Ensure the relevant API key env var (e.g. OPENAI_API_KEY or the provider's equivalent) is set in the runtime environment.
- If invoking LLM steps directly in tests, attach flow deps with a model to the context instead of passing a bare context.Background().
- Replace the LLM step with a plain Run function if no model is intended for this flow.
Example fix
// before
f := flow.New(flow.Steps(flow.LLM("Summarize: {{.Data}}")))
// after
f := flow.New(
flow.Provider("openai"),
flow.APIKey(os.Getenv("OPENAI_API_KEY")),
flow.Steps(flow.LLM("Summarize: {{.Data}}")),
) Defensive patterns
Strategy: validation
Validate before calling
if flowDepsFrom(ctx) == nil || flowDepsFrom(ctx).model == nil {
return errors.New("flow model not configured: set Provider/APIKey before using LLM steps")
} Type guard
func hasFlowModel(ctx context.Context) bool {
d := depsFrom(ctx)
return d != nil && d.model != nil
} Try / catch
state, err := step(ctx, in)
if err != nil {
if strings.Contains(err.Error(), "requires a flow model") {
// configure model and retry, or skip LLM step
}
return err
} Prevention
- Always set Provider and APIKey options when a flow contains LLM steps
- Source provider API keys from env at startup and fail fast if unset
- In tests, build a helper that attaches deps with a model to the test context
- Cover each LLM step in an integration test so missing config surfaces in CI
When it happens
Trigger: Calling flow.LLM(prompt) as a StepFunc when the flow was built without Provider/APIKey options, or when the context passed to the step carries no flow deps (d == nil), e.g. invoking the step function directly outside a configured Flow run.
Common situations: Developers add an LLM step to a flow but forget to configure the model options (Provider/APIKey) on the flow; or they test the step function standalone with a plain context.Context that never had deps attached; or the provider env credentials are missing so the model was never constructed.
Related errors
- flow: LLMGrader requires a flow model (set Provider/APIKey)
- flow: UntilLLM requires a flow model (set Provider/APIKey)
- flow %s has no checkpoint configured
- flow: step %q has no Run function
- flow: step %d has an empty name
AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01).
Data as JSON: /api/errors/34ccaaaa17fe330d.
Report an issue: GitHub.