Skip to content

Update encodable type class to have optional prompt prefix (closes #498)#501

Merged
eb8680 merged 1 commit intomasterfrom
kg-prompt-instructions-prefix
Jan 21, 2026
Merged

Update encodable type class to have optional prompt prefix (closes #498)#501
eb8680 merged 1 commit intomasterfrom
kg-prompt-instructions-prefix

Conversation

@kiranandcode
Copy link
Contributor

  • Updates EncodableAs to have an optional class method encoding_instructions
class EncodableAs[T, U](ABC):
    ...
    @classmethod
    def encoding_instructions(cls) -> str | None:
        """Optional instructions to be prefixed onto synthesis prompts to tune the encoding of the result."""
        return None
  • Updates the default implementation for format_model_input to retrieve the encodable type for the return type and append a prompt prefix if encoding instructions is defined.
    ret_type = template.__signature__.return_annotation
    origin = typing.get_origin(ret_type)
    ret_type = ret_type if origin is None else origin
    ret_type_encoder = type_to_encodable_type(ret_type)
    prompt_prefix = ret_type_encoder.encoding_instructions()

    if prompt_prefix:
        prefix: list[ChatCompletionTextObject] = [
            {"type": "text", "text": prompt_prefix}
        ]
        prompt = prefix + prompt

Closes #498

@eb8680 eb8680 merged commit 75c34d5 into master Jan 21, 2026
6 checks passed
@eb8680 eb8680 deleted the kg-prompt-instructions-prefix branch January 21, 2026 21:24
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.

Encodables should include optional prompt prefixes

2 participants