micro/go-micro · error
flow: LLMGrader requires a flow model (set Provider/APIKey)
Error message
flow: LLMGrader requires a flow model (set Provider/APIKey)
What it means
flow.LLMGrader returns a Grader that grades output with the flow's configured model, retrieved from the context via depsFrom(ctx). This error is returned at grading time when no flow model is present in the context — i.e. the grader is running outside a configured flow or the flow has no Provider/APIKey set. The LLM call is never attempted.
Source
Thrown at flow/verify.go:121
select {
case <-time.After(o.Backoff):
case <-ctx.Done():
return last, ctx.Err()
}
}
}
return stateWithVerification(last, false, feedback, o.MaxAttempts)
}
}
// LLMGrader returns a grader that asks the flow model to judge the latest output
// against rubric. The model should answer with pass/fail plus short feedback.
// It reuses the flow's configured model, so it must run inside a flow.
func LLMGrader(rubric string) Grader {
return func(ctx context.Context, out State) (bool, string, error) {
d := depsFrom(ctx)
if d == nil || d.model == nil {
return false, "", fmt.Errorf("flow: LLMGrader requires a flow model (set Provider/APIKey)")
}
prompt := fmt.Sprintf("Grade the latest result against this rubric:\n%s\n\nLatest result:\n%s\n\nAnswer with PASS or FAIL on the first line, followed by one short feedback sentence.", rubric, out.String())
resp, err := d.model.Generate(ctx, &ai.Request{Prompt: prompt})
if err != nil {
return false, "", err
}
reply := resp.Answer
if reply == "" {
reply = resp.Reply
}
return parseGrade(reply)
}
}
func parseGrade(reply string) (bool, string, error) {
text := strings.TrimSpace(reply)
if text == "" {
return false, "", fmt.Errorf("flow: LLMGrader returned an empty grade")View on GitHub (pinned to 24529f1404)
Solutions
- Configure the flow's model by setting Provider and APIKey (and any model options) in the flow configuration before running it.
- Run the grader only inside a flow execution so the injected dependencies (depsFrom(ctx)) are available.
- If testing, inject a mock model into the context/flow deps rather than calling the grader with a plain context.
Example fix
// before
f := flow.New() // model never configured
f.Step(flow.Verify(body, flow.LLMGrader(rubric)))
// after
f := flow.New(flow.WithModel("openai", os.Getenv("OPENAI_API_KEY")))
f.Step(flow.Verify(body, flow.LLMGrader(rubric))) Defensive patterns
Strategy: validation
Validate before calling
if os.Getenv("PROVIDER") == "" || os.Getenv("API_KEY") == "" {
return errors.New("flow model not configured: set Provider and APIKey before using LLMGrader")
} Try / catch
out, err := step(ctx, in)
if err != nil && strings.Contains(err.Error(), "LLMGrader requires a flow model") {
// configure the flow model (Provider/APIKey) and re-run
} Prevention
- Set Provider/APIKey (or a WithModel option) in every flow that uses LLMGrader.
- Fail fast at startup with a config check rather than mid-run.
- In tests, inject a mock model into flow deps instead of running with a bare context.
When it happens
Trigger: Running an LLMGrader step when the flow's model was never configured (Provider/APIKey empty), or invoking the grader function directly with a bare context.Context that lacks flow dependency injection.
Common situations: Testing the grader outside a real flow run; forgetting to set the flow's model options; building a flow programmatically where model setup was skipped; calling the grader from a non-flow goroutine with a fresh context.
Related errors
- LLM step 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/c38fe768229a1432.
Report an issue: GitHub.