Skip to content

bug(stdlib): @generative stub signature corrupted under from __future__ import annotations #1503

Closed

Description

@planetf1

Summary

describe_function() and get_argument() in mellea/stdlib/components/genstub.py call inspect.signature(func) without eval_str=True. When the caller's module has from __future__ import annotations (PEP 563), every annotation on func is a string rather than a real type object, which corrupts the @generative stub prompt in two independent ways:

  1. describe_function() renders the raw annotation strings straight into the prompt, e.g. def extract_requirements(product_description: 'str') -> 'list[Requirement]': instead of the resolved def extract_requirements(product_description: str) -> list[Requirement]:. The quote characters leak into the LLM-facing template verbatim.
  2. get_argument() checks param.annotation is str to decide whether to quote a value for the prompt. Under PEP 563 the annotation is the string "str", not the str type, so the check silently fails and string arguments are rendered unquoted.

Reproduction

from __future__ import annotations
from dataclasses import dataclass
from mellea.stdlib.components.genstub import describe_function

@dataclass
class Requirement:
    id: str
    text: str

def extract_requirements(product_description: str) -> list[Requirement]:
    """Extract requirements from a product description."""

print(describe_function(extract_requirements)["signature"])
# def extract_requirements(product_description: 'str') -> 'list[Requirement]':

Impact

Only templates that render function.signature directly are exposed to point 1 (e.g. mellea/templates/prompts/default/GenerativeStub.jinja2); templates that never render the raw signature are unaffected. This means any prompt-template A/B comparison built on PEP 563-style fixture modules is asymmetrically biased against signature-rendering templates, independent of the templates' actual quality. Point 2 affects every template, since it corrupts argument values rather than the signature.

Activity

  1. self-assigned this
    on Aug 6, 2026
  2. added a commit that references this issue on Aug 6, 2026
    c472907
  3. added 2 commits that reference this issue on Aug 11, 2026
    7f8e624
    7840e8e
  4. added a commit that references this issue on Aug 12, 2026
    04c177d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions