Repository navigation
Description
Summary
The default prompt template for @generative stubs uses a "pretend you are a function" framing (imitate the output of this Python function). Smaller Granite models (4.1-3B and below) have trouble following it. In hands-on use, rewriting the template to a plain "reply in JSON formatted as {X}" instruction produced markedly better results at those sizes.
We should benchmark the current template against simpler variants across model sizes and update the default if the results hold, likely as a per-model-family template rather than one global default (the template system already supports per-family overrides).
Note: the output schema is already enforced via structured output, so this isabout prompt framing helping smaller models produce the right content, not about malformed JSON.
Encountered while using @generative to extract a list of requirements that were then verified with the requirement-check adapter (aLoRA).
Open question: per-call template arg?
We could expose a template override on the stub, but making that the primary fix cuts against the @generative premise of "write a normal function, we handle the prompting." Better default (or per-family default) is the real fix; a per-call override, if added, should be a documented escape hatch only.
Acceptance criteria
- Eval comparing the current template against direct variants across at least two model sizes.
- Default template updated (globally or per family) based on results.
- Any per-call override documented as an advanced escape hatch, not the recommended path.
Starting points
mellea/stdlib/components/genstub.py(@generative)mellea/templates/prompts/default/GenerativeStub.jinja2
Activity
fix(stdlib): drop stale issue ref and guard PEP 563 test preconditions
fix(stdlib): resolve postponed annotations in generative stub signatu…
planetf1 commentedon Aug 11, 2026
One prompt-legibility detail for whoever picks up the template redesign, since it interacts with small-model behaviour specifically.
#1509 fixes #1529, where a
@generativestub with aTYPE_CHECKING-only return annotation failed at decoration time. The fix leaves an unresolvable return annotation as its postponed string, sodescribe_functionrenders it quoted:That was a deliberate choice over the alternative of omitting the return type entirely — a quoted type still names it, and the pre-#1504 behaviour had quotes on every annotation, so this is a strict subset of a state the project shipped for a long time.
The residual risk belongs here rather than in #1509: a smaller model may read
-> 'Decimal'as "returns a string containing Decimal" rather than as a forward reference. Larger models handle the distinction; that gap is exactly this issue's subject.Worth noting it only affects stubs whose return type is
TYPE_CHECKING-only or forward-referenced, not the common case. Rendering it unquoted is not cleanly reachable —inspect.formatannotationalways quotes a string annotation, and forcing a bare name needs a synthetic type that falsely claims__module__ = "builtins". If the redesign moves to building the signature text explicitly rather than viastr(inspect.Signature), that constraint disappears and the return type could be rendered bare.