Skip to content

Make ParameterMapper generic on Content type #186

@Kamilbenkirane

Description

@Kamilbenkirane

Problem

ParameterMapper.parse_output() in src/celeste/parameters.py uses Any for its content parameter and return type. This was introduced as a pragmatic fix in #142 to bridge the type boundary between the generic Content type parameter on ModalityClient and the text-specific parse_output method.

While Any is accurate for the base implementation (it's an identity function), it loses type safety — callers and overrides get no static type checking on the content flowing through parse_output.

Root cause

ParameterMapper is not generic. It was originally designed with TextContent hardcoded in parse_output, because structured output parsing only applies to text. But now that _transform_output() is called at the base _predict() pipeline level (for all modalities), the parameter system needs to be content-type-agnostic.

Proposed fix

Make ParameterMapper generic on a Content type parameter, following the existing codebase convention (PEP 695 syntax, semantic names):

class ParameterMapper[Content](ABC):
    def parse_output(self, content: Content, value: object | None) -> Content:
        return content

Then propagate through the chain:

  • FieldMapper[Content](ParameterMapper[Content])
  • parameter_mappers() -> list[ParameterMapper[Content]] on ModalityClient
  • _transform_output(content: Content, ...) -> Content — no Any needed

Affected files

  • src/celeste/parameters.py — make ParameterMapper and FieldMapper generic
  • src/celeste/client.py — update parameter_mappers() return type
  • 70+ ParameterMapper subclasses — add type parameter
  • 40+ FieldMapper subclasses — add type parameter
  • 7 parse_output overrides — change TextContent to Content
  • All parameter_mappers() implementations — update return type

Impact

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