Skip to content

feat(types): bridge normalized LM outputs - #63

Draft
isaacbmiller wants to merge 1 commit into
isaac/adapter-simplify-basefrom
reviewable/adapter-simplify-01-type-bridges
Draft

feat(types): bridge normalized LM outputs#63
isaacbmiller wants to merge 1 commit into
isaac/adapter-simplify-basefrom
reviewable/adapter-simplify-01-type-bridges

Conversation

@isaacbmiller

@isaacbmiller isaacbmiller commented May 27, 2026

Copy link
Copy Markdown

Summary

This is PR 1 of 2 in the adapter simplification stack.

It adds the type-side bridge that lets adapter parsing consume normalized LMOutput values without requiring the LM/client boundary changes from the earlier version of this work.

Key changes:

  • Adds Type.parse_lm_output(output) as the normalized output hook, with a default bridge back to existing parse_lm_response(...) implementations.
  • Teaches Reasoning and Citations to parse directly from normalized LMOutput parts.
  • Normalizes citation dictionaries so normalized citation parts map cleanly back into the current Citations.Citation model.
  • Preserves explicit legacy content blocks when normalized parts are projected back to OpenAI-shaped history dictionaries.
  • Allows LMRequest.from_call(...) to accept existing OpenAI-shaped message dictionaries as message items in direct-call paths.

Why This Is Separate

The next PR simplifies dspy/adapters/base.py to parse LMResponse directly. That only makes sense if native response types can already read normalized LMOutput values. This PR creates that type contract first, while keeping the existing legacy type methods in place.

Review Notes

The important invariant is that this is a bridge, not a public LM boundary change. It should not require changes to dspy.LM, BaseLM, or provider clients.

History has two surfaces here:

  • dspy.History inputs are still signature-shaped adapter records and are rendered by adapters before the LM request is built.
  • LM inspect-history still exposes OpenAI-shaped message dictionaries by projecting normalized LMParts back into the legacy display shape.

Validation

  • uv run --frozen ruff check dspy/adapters/types/base_type.py dspy/adapters/types/citation.py dspy/adapters/types/reasoning.py dspy/core/types.py
  • uv run --frozen pytest --deno -q tests/core/test_types.py tests/streaming/test_streaming.py::test_streaming_allows_custom_streamable_type
    • 21 passed, 14 warnings

Top of stack validation is in PR 2.

@isaacbmiller
isaacbmiller force-pushed the reviewable/adapter-simplify-01-type-bridges branch from 1d4c395 to 188e60a Compare May 27, 2026 05:28
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.

1 participant