Skip to content

[Feature]: Add finish reason support to Response #246

Description

@sepandhaghighi

Describe the feature you want to add

Add an optional finish_reason field to the Response class to indicate why an LLM stopped generating a response. The field should support both predefined finish reasons (e.g., stop, length, tool_calls) and custom provider-specific values. It should be fully supported by constructors, serialization (to_dict(), to_json()), deserialization (from_json()), equality checks, and public accessors.

Describe your proposed solution

Introduce an optional finish_reason attribute that accepts either a FinishReason enum or a string. Internally, always store the value as a string to simplify serialization and ensure compatibility with existing and future LLM providers. When an enum is provided, store its corresponding string value. This implementation should be fully backward-compatible, allowing existing code and response objects to continue working without modification.

Describe alternatives you've considered, if relevant

No response

Additional context

No response

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions