Skip to content

fix: widen generation function specs to match Context.normalize/2#441

Merged
mikehostetler merged 2 commits intoagentjido:mainfrom
Nickcom4:fix/434-widen-generation-specs
Feb 20, 2026
Merged

fix: widen generation function specs to match Context.normalize/2#441
mikehostetler merged 2 commits intoagentjido:mainfrom
Nickcom4:fix/434-widen-generation-specs

Conversation

@Nickcom4
Copy link
Contributor

Summary

  • Adds Context.prompt() type alias that matches all types accepted by Context.normalize/2
  • Updates @spec on all 8 generation functions to use Context.prompt() instead of the overly narrow String.t() | list()
  • Eliminates Dialyzer false-positive warnings in downstream apps that pass Context.t() structs (the recommended usage pattern)

Affected functions

All 8 specs in ReqLLM.Generation:

  • generate_text/3, generate_text!/3
  • stream_text/3, stream_text!/3
  • generate_object/4, generate_object!/4
  • stream_object/4, stream_object!/4

The Context.prompt() type

@type prompt ::
        String.t()
        | Message.t()
        | t()
        | map()
        | [String.t() | Message.t() | t() | map()]

This exactly mirrors the spec on Context.normalize/2 (lines 103-110 of context.ex).

Precedent

Same class of fix as PR #301 which widened the object_schema parameter spec for generate_object.

Test plan

  • mix compile --warnings-as-errors passes (zero warnings)
  • Context.prompt() type matches Context.normalize/2 spec exactly
  • Using a named type alias is DRYer than repeating the union in 8 places

Closes #434

The @SPEC for all 8 generation functions declared the messages
parameter as `String.t() | list()`, but Context.normalize/2
accepts Context.t(), Message.t(), and map() as well. This caused
Dialyzer false-positive warnings in downstream apps using Context
structs (the recommended pattern).

Adds a `Context.prompt()` type alias matching normalize/2's input
types, and references it from all 8 specs in Generation.

Closes agentjido#434
@mikehostetler mikehostetler merged commit 661a337 into agentjido:main Feb 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Generation function specs too narrow for messages parameter

2 participants