Skip to content

Python: apply input_variables defaults when rendering prompt templates - #14459

Open
Manohar Paturi (ManoharPaturi) wants to merge 2 commits into
microsoft:mainfrom
ManoharPaturi:fix/prompt-input-variable-defaults
Open

Manohar Paturi (ManoharPaturi) wants to merge 2 commits into
microsoft:mainfrom
ManoharPaturi:fix/prompt-input-variable-defaults

Conversation

@ManoharPaturi

Copy link
Copy Markdown

Fixes #14458.

KernelPromptTemplate.render now seeds any missing argument with the declared input_variables default before rendering (case-insensitive name check, explicit arguments always win, falsy defaults untouched so the existing empty-string behavior for unset defaults stays).

2 regression tests: default applies when the argument is missing, and an explicit argument overrides the default. The default-applies test fails on main. Full prompt_template suite green (13 passed), ruff clean.

…riptions

build_model_schema() preferred FieldInfo.metadata over FieldInfo.description
when deriving field descriptions. In pydantic v2, FieldInfo.metadata is a
list of constraint objects (annotated_types.Ge, Gt, ...), so for any field
declared with a constraint (e.g. Field(description=..., ge=0)) the real
description was replaced by the constraint object. The resulting schema
carried a non-string 'description' and json.dumps() of the function-calling
tool payload failed with 'TypeError: Object of type Ge is not JSON
serializable'.

Only treat str and dict-with-'description' entries in metadata as
descriptions (these come from Annotated metadata), and fall back to
FieldInfo.description otherwise.
The per-variable default was validated and exported as metadata but never
consulted at render time, so a missing argument rendered as an empty
string instead of the declared default. Seed missing arguments with
their defaults before rendering; explicit arguments always win.

Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

Python: input_variables default values are never applied when rendering templates

2 participants