Skip to content

Add model config to prompt (backend and docs change)#19174

Merged
chenmoneygithub merged 15 commits intomlflow:masterfrom
chenmoneygithub:prompt-model-config
Dec 8, 2025
Merged

Add model config to prompt (backend and docs change)#19174
chenmoneygithub merged 15 commits intomlflow:masterfrom
chenmoneygithub:prompt-model-config

Conversation

@chenmoneygithub
Copy link
Contributor

@chenmoneygithub chenmoneygithub commented Dec 2, 2025

🛠 DevTools 🛠

Open in GitHub Codespaces

Install mlflow from this PR

# mlflow
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19174/merge
# mlflow-skinny
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19174/merge#subdirectory=libs/skinny

For Databricks, use the following command:

%sh curl -LsSf https://raw.githubusercontent.com/mlflow/mlflow/HEAD/dev/install-skinny.sh | sh -s pull/19174/merge

Related Issues/PRs

#xxx

What changes are proposed in this pull request?

Prompt should have model configs, because models use different prompts.

How is this PR tested?

  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests

Does this PR require documentation update?

  • No. You can skip the rest of this section.
  • Yes. I've updated:
    • Examples
    • API references
    • Instructions

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/tracking: Tracking Service, tracking client APIs, autologging
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflows
  • area/gateway: MLflow AI Gateway client APIs, server, and third-party integrations
  • area/prompts: MLflow prompt engineering features, prompt templates, and prompt management
  • area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality
  • area/projects: MLproject format, project running backends
  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages

How should the PR be classified in the release notes? Choose one:

  • rn/none - No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" section
  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

Should this PR be included in the next patch release?

Yes should be selected for bug fixes, documentation updates, and other small changes. No should be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.

What is a minor/patch release?
  • Minor release: a release that increments the second part of the version number (e.g., 1.2.0 -> 1.3.0).
    Bug fixes, doc updates and new features usually go into minor releases.
  • Patch release: a release that increments the third part of the version number (e.g., 1.2.0 -> 1.2.1).
    Bug fixes and doc updates usually go into patch releases.
  • Yes (this PR will be cherry-picked and included in the next patch release)
  • No (this PR will be included in the next minor release)

@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

@chenmoneygithub Thank you for the contribution! Could you fix the following issue(s)?

⚠ DCO check

The DCO check failed. Please sign off your commit(s) by following the instructions here. See https://github.com/mlflow/mlflow/blob/master/CONTRIBUTING.md#sign-your-work for more details.

@chenmoneygithub chenmoneygithub changed the title Add model config to prompt [WIP] Add model config to prompt (backend and docs change) Dec 2, 2025
@github-actions github-actions bot added area/prompts MLflow Prompt Registry and Optimization rn/feature Mention under Features in Changelogs. labels Dec 2, 2025
@chenmoneygithub chenmoneygithub changed the title [WIP] Add model config to prompt (backend and docs change) Add model config to prompt (backend and docs change) Dec 2, 2025
@harupy
Copy link
Member

harupy commented Dec 3, 2025

/review


🚀 Review workflow started


✅ Review completed.

Review Output

Review Complete

I've reviewed PR #19174 "Add model config to prompt (backend and docs change)" and found 3 issues:

  1. Type annotation style (line 91-98 in prompt_version.py): Using str | None union syntax instead of Optional[str] for consistency with the rest of the codebase

  2. Comment inconsistency (line 1516 in rest_store.py): Comment says "Convert ModelConfig" but should say "Convert PromptModelConfig" to match the class name

  3. Documentation typo (line 580 in client.py): Extra space in "model-specific configuration"

All comments have been posted to the PR with suggested fixes. The overall code quality is good, with comprehensive tests, proper validation, and clear documentation. The implementation correctly handles model configuration as a mutable property stored in tags.

@mlflow mlflow deleted a comment from github-actions bot Dec 3, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds model configuration support to the MLflow Prompt Registry, allowing users to store model-specific settings (e.g., model name, temperature, max_tokens) alongside prompt templates. This ensures reproducibility by versioning both prompts and their associated model parameters together.

Key Changes:

  • Introduces a new PromptModelConfig dataclass with validation for common LLM parameters (temperature, max_tokens, top_p, etc.)
  • Adds model_config parameter to prompt registration and management APIs
  • Implements set_prompt_model_config() and delete_prompt_model_config() for mutable model configuration management

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
mlflow/entities/model_registry/prompt_version.py Adds PromptModelConfig dataclass with validation and model_config property to PromptVersion
mlflow/entities/model_registry/__init__.py Exports PromptModelConfig for public API
mlflow/genai/prompts/__init__.py Adds model_config parameter to register_prompt() and new functions set_prompt_model_config() and delete_prompt_model_config()
mlflow/genai/__init__.py Exports new model config management functions
mlflow/tracking/client.py Adds model_config parameter support in client's register_prompt() method
mlflow/tracking/_model_registry/fluent.py Adds model_config parameter support in fluent API
mlflow/store/model_registry/abstract_store.py Implements model_config handling in create_prompt_version()
mlflow/store/_unity_catalog/registry/rest_store.py Implements model_config handling for Unity Catalog backend
tests/genai/prompts/test_prompts.py Comprehensive tests for model config registration, loading, updating, and deletion
tests/entities/test_prompt.py Unit tests for PromptModelConfig validation, serialization, and integration
docs/docs/genai/prompt-registry/index.mdx Extensive documentation covering model config usage, validation, and provider-specific parameters

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@harupy
Copy link
Member

harupy commented Dec 3, 2025

/review rewrite PromptModelConfig using pydantic. Flag duplicate imports. Suggest using pytest.mark.parametrize.


🚀 Review workflow started


✅ Review completed.

Review Output

I've completed the PR review for PR #19174. Here's a summary of the issues found and comments added:

Review Summary

5 comments added:

  1. PromptModelConfig implementation (mlflow/entities/model_registry/prompt_version.py:31-197)

    • Suggested rewriting PromptModelConfig using Pydantic instead of dataclass for better validation, automatic type coercion, and consistency with the codebase (the file already imports pydantic)
    • Pydantic provides cleaner validation with Field constraints and better error messages
  2. Duplicate import Fix example file path #1 (mlflow/store/_unity_catalog/registry/rest_store.py:19-22)

    • PromptModelConfig is imported but seems redundant - flagged for review
  3. Duplicate import models.rst typo #2 (mlflow/store/model_registry/abstract_store.py:796-811)

    • MODEL_CONFIG_TAG_KEY and PromptModelConfig imported inside function but already at module level (line 16)
    • Provided suggestion to remove redundant import
  4. Duplicate import TypeError: __init__() got an unexpected keyword argument 'file' #3 (mlflow/tracking/client.py:658-671)

    • Same issue: MODEL_CONFIG_TAG_KEY and PromptModelConfig imported inside function but already at module level (line 49)
    • Provided suggestion to remove redundant import
  5. pytest.mark.parametrize suggestion (tests/entities/test_prompt.py:316-350)

    • The validation tests check many different error cases separately
    • Suggested consolidating into a single parametrized test for better maintainability and clearer failure diagnostics

All comments follow the requested focus areas and include the "🤖 Generated with Claude Code" signature.

registry_api._load_prompt_cached.cache_clear()


@experimental(version="3.5.0")
Copy link
Member

Choose a reason for hiding this comment

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

can you fix the version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am using 3.8.0, which is the next minor release, let me know if that's the correct approach!

PromptVersionTag = ModelVersionTag


MODEL_CONFIG_TAG_KEY = "_mlflow_prompt_model_config"
Copy link
Member

Choose a reason for hiding this comment

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

Lets rename the key to follow mlflow/utils/mlflow_tags.py, and move it in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

from pydantic import BaseModel, Field


class PromptModelConfig(BaseModel):
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need this class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Functionality-wise a wildcard dict can do the job, but I don't like that approach, which has no validation and format constraint. Also it's hard to document it in the docstring: model_config: dict[str, Any] is confusing.

Comment on lines +338 to +339
# Test valid values
PromptModelConfig(temperature=0.0, max_tokens=1000, top_p=0.9, top_k=50)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Test valid values
PromptModelConfig(temperature=0.0, max_tokens=1000, top_p=0.9, top_k=50)
def test_...
# Test valid values
PromptModelConfig(temperature=0.0, max_tokens=1000, top_p=0.9, top_k=50)

can we separate this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this line is actually redundant, and has been covered by other test cases, removed!

LATEST_CHECKPOINT_ARTIFACT_TAG_KEY = "mlflow.latest_checkpoint_artifact"

# For prompt model configuration
MLFLOW_PROMPT_MODEL_CONFIG = "_mlflow_prompt_model_config"
Copy link
Member

Choose a reason for hiding this comment

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

can we use the same format as other tags?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, missed this one, thanks for catching!

frequency_penalty: float | None = None
presence_penalty: float | None = None
stop_sequences: list[str] | None = None
extra_params: dict[str, Any] = Field(default_factory=dict)
Copy link
Member

@harupy harupy Dec 5, 2025

Choose a reason for hiding this comment

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

can extra_params contain the known fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes good question - it's allowed and would work fine, but not the good practice because it can break the UI rendering or so.

Copy link
Member

@harupy harupy left a comment

Choose a reason for hiding this comment

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

Left a few more comments/questions, otherwise LGTM :)

Copy link
Member

@harupy harupy left a comment

Choose a reason for hiding this comment

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

Left a few more comments, otherwise LGTM!

Comment on lines +122 to +131
known_fields = {
"model_name",
"temperature",
"max_tokens",
"top_p",
"top_k",
"frequency_penalty",
"presence_penalty",
"stop_sequences",
}
Copy link
Member

Choose a reason for hiding this comment

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

Any pydantic model field we can leverage to de-hardcode these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes good call!

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

Documentation preview for cc4fc4f is available at:

Changed Pages (1)

More info
  • Ignore this comment if this PR does not change the documentation.
  • The preview is updated when a new commit is pushed to this PR.
  • This comment was created by this workflow run.
  • The documentation was built by this workflow run.

@chenmoneygithub chenmoneygithub added this pull request to the merge queue Dec 8, 2025
Merged via the queue into mlflow:master with commit 339fc03 Dec 8, 2025
47 checks passed
@chenmoneygithub chenmoneygithub deleted the prompt-model-config branch December 8, 2025 19:53
)
"""

model_name: str | None = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

@chenmoneygithub Sorry for the late review! How do you feel about making model_name required? I think it's unlikely that users want to configure other parameters without configuring model name. Also as we discussed, can we add provider name?

LATEST_CHECKPOINT_ARTIFACT_TAG_KEY = "mlflow.latest_checkpoint_artifact"

# For prompt model configuration
MLFLOW_PROMPT_MODEL_CONFIG = "mlflow.prompt.modelConfig"
Copy link
Collaborator

Choose a reason for hiding this comment

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

@chenmoneygithub Can we replace "." with "_" and move this config to mlflow/prompt/constants.py? Managed prompt registry does not allow to have "." in the tag key name.

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

Labels

area/prompts MLflow Prompt Registry and Optimization rn/feature Mention under Features in Changelogs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants