Skip to content

ComponentTool(AnswerJoiner()) raises SchemaGenerationError (unresolved ExtractedAnswer.Span) #12950

Closed as not planned

Description

@michaelkillgta

Description

ComponentTool(component=AnswerJoiner()) fails at construction with SchemaGenerationError. The cause is an unresolved forward reference to the nested class ExtractedAnswer.Span on ExtractedAnswer.document_offset / context_offset.

AnswerJoiner is the standard multi-branch answer merge component, so the documented ComponentTool → Agent path cannot expose answer joining to an LLM.

Environment

  • haystack-ai==3.2.0
  • Python 3.13 / pydantic v2

Minimal repro

from haystack.components.joiners import AnswerJoiner
from haystack.tools import ComponentTool
from haystack.tools.errors import SchemaGenerationError

try:
    ComponentTool(component=AnswerJoiner())
    print("UNEXPECTED: schema built")
except SchemaGenerationError as e:
    print(type(e).__name__, e)
    # Failed to create JSON schema for the run method of Component 'AnswerJoiner'
    # underlying: PydanticUserError … define Span, then call run.model_rebuild()

Expected

ComponentTool(AnswerJoiner()) succeeds (or skips unschematizable nested fields with a clear warning), matching other joiners that can be wrapped.

Actual

SchemaGenerationError("Failed to create JSON schema for the run method of Component 'AnswerJoiner'") caused by unresolved Span.

Root cause (pointer)

AnswerJoiner.run takes Variadic[list[GeneratedAnswer | ExtractedAnswer]]. ExtractedAnswer annotates offsets as Optional["Span"] where Span is the nested class ExtractedAnswer.Span. Pydantic schema generation for the tool wrapper does not rebuild / resolve that forward ref.

Suggested fix direction

Ensure ExtractedAnswer / nested Span is fully defined before schema generation (model_rebuild()), or qualify the annotation as Optional[ExtractedAnswer.Span] / a module-level Span type so tool wrapping succeeds.

Activity

  1. sjrl commented on Sep 25, 2026

    @sjrl
    Contributor

    @michaelkillgta thanks for opening! I wanted to ask could you tell a use case where you wanted to use the AnswerJoiner as a ComponentTool in the Agent? I can't currently think of a good use case for this as a tool.

  2. testbeeai-ui commented on Sep 25, 2026

    @testbeeai-ui

    Thanks @sjrl — fair question. I don’t have a strong production case for exposing AnswerJoiner itself as an Agent tool. I hit this while checking which built-in components fail under ComponentTool, and AnswerJoiner is the obvious multi-branch answer merge.

    So the report is really about schema generation (ExtractedAnswer.Span forward ref), not a product need for “join answers as a tool.” Happy to close this as not-a-priority for Agent tooling if you’d rather keep Joiners pipeline-only — or I can leave it open as a ComponentTool footgun for anyone who wraps answer types. Prefer which?

  3. michaelkillgta commented on Sep 25, 2026

    @michaelkillgta
    Author

    Thanks @sjrl — fair question. I don’t have a strong production case for exposing AnswerJoiner itself as an Agent tool. I hit this while checking which built-in components fail under ComponentTool, and AnswerJoiner is the obvious multi-branch answer merge.

    So the report is really about schema generation (ExtractedAnswer.Span forward ref), not a product need for “join answers as a tool.” Happy to close this as not-a-priority for Agent tooling if you’d rather keep Joiners pipeline-only — or I can leave it open as a ComponentTool footgun for anyone who wraps answer types. Prefer which?

  4. sjrl commented on Sep 25, 2026

    @sjrl
    Contributor

    Thanks for the extra context. Given that there isn’t a clear Agent use case for AnswerJoiner at the moment, I’d prefer to close the issue for now rather than treat this as a priority for ComponentTool.

    The schema-generation issue is still useful to have identified though, especially if similar answer types show up in more relevant tooling paths later. We can always revisit it if that happens.

  5. michaelkillgta commented on Sep 25, 2026

    @michaelkillgta
    Author

    Thanks @sjrl — agreed on closing for now. Glad the schema-generation footgun is on the record if similar types show up on a hotter path later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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