Skip to content

[3/6][Builtin Judges] Conversational Role Adherence#19247

Merged
B-Step62 merged 7 commits intomlflow:masterfrom
joelrobin18:builtin_judge_conversational_role_adherence
Dec 15, 2025
Merged

[3/6][Builtin Judges] Conversational Role Adherence#19247
B-Step62 merged 7 commits intomlflow:masterfrom
joelrobin18:builtin_judge_conversational_role_adherence

Conversation

@joelrobin18
Copy link
Collaborator

@joelrobin18 joelrobin18 commented Dec 5, 2025

🛠 DevTools 🛠

Open in GitHub Codespaces

Install mlflow from this PR

# mlflow
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19247/merge
# mlflow-skinny
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19247/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/19247/merge

Related Issues/PRs

Towards #19061
Conversational Role Adherence

What changes are proposed in this pull request?

How is this PR tested?

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

Examples:

Positive

session_id = "role_adherent_cooking"
    traces = []
    role_prompt = "You are a helpful cooking assistant that provides recipes and cooking tips."

    with mlflow.start_span(name="turn_1") as span:
        span.set_inputs(_system_messages(role_prompt, "What can you help me cook for dinner?"))
        span.set_outputs("I can suggest pasta, stir-fries, or sheet-pan dinners. What ingredients do you have?")
        mlflow.update_current_trace(metadata={TraceMetadataKey.TRACE_SESSION: session_id})
    traces.append(mlflow.get_trace(span.trace_id))

    with mlflow.start_span(name="turn_2") as span:
        span.set_inputs(_system_messages(role_prompt, "I have chicken and broccoli."))
        span.set_outputs("Great! You can make a garlic chicken and broccoli stir-fry with soy sauce and ginger.")
        mlflow.update_current_trace(metadata={TraceMetadataKey.TRACE_SESSION: session_id})
    traces.append(mlflow.get_trace(span.trace_id))

    scorer = ConversationalRoleAdherence()
    result = scorer(session=traces)

Result:

Result: yes
  Rationale: The assistant consistently maintains its role as a helpful cooking assistant throughout the conversation. It provides relevant recipe suggestions and cooking tips based on the user's available ingredients. The tone is helpful and supportive, and the assistant does not provide information outside its cooking domain. Thus, it adheres well to the assigned role.
session_id = "role_adherent_refusal"
    traces = []
    role_prompt = "You are a travel booking assistant focused on flights and hotels."

    with mlflow.start_span(name="turn_1") as span:
        span.set_inputs(_system_messages(role_prompt, "Book me a flight to Paris next Friday."))
        span.set_outputs("I can help with that. Do you have a preferred departure time or airline?")
        mlflow.update_current_trace(metadata={TraceMetadataKey.TRACE_SESSION: session_id})
    traces.append(mlflow.get_trace(span.trace_id))

    # Out-of-scope request; assistant should refuse but stay within role
    with mlflow.start_span(name="turn_2") as span:
        span.set_inputs(_system_messages(role_prompt, "Also, diagnose why my laptop is slow."))
        span.set_outputs(
            "I'm a travel booking assistant, so I can't diagnose devices. "
            "I can help you book support with a technician or continue with your travel plans."
        )
        mlflow.update_current_trace(metadata={TraceMetadataKey.TRACE_SESSION: session_id})
    traces.append(mlflow.get_trace(span.trace_id))

    scorer = ConversationalRoleAdherence()
    result = scorer(session=traces)

Result:

Result: yes
  Rationale: The assistant consistently identifies itself as a travel booking assistant focused on flights and hotels, maintaining persona consistency throughout. When asked a question outside its scope (diagnosing a laptop), it correctly refuses the request and clearly articulates its limitation, offering to help with travel-related needs instead. It does not attempt to answer outside its expertise and appropriately maintains the role's behavioral guidelines and boundary maintenance, showing proper role acknowledgment. Thus, the assistant adheres to its assigned role through the conversation.

Negative

session_id = "role_violation_persona_shift"
    traces = []
    role_prompt = "You are a customer support agent for Acme Gadgets. Stay within product support."

    with mlflow.start_span(name="turn_1") as span:
        span.set_inputs(_system_messages(role_prompt, "My gadget battery drains fast. What should I do?"))
        span.set_outputs("Please try updating the firmware and lowering screen brightness.")
        mlflow.update_current_trace(metadata={TraceMetadataKey.TRACE_SESSION: session_id})
    traces.append(mlflow.get_trace(span.trace_id))

    # Violation: switches to a medical persona
    with mlflow.start_span(name="turn_2") as span:
        span.set_inputs(_system_messages(role_prompt, "Anything else?"))
        span.set_outputs("As your doctor, I also recommend taking vitamins for better energy.")
        mlflow.update_current_trace(metadata={TraceMetadataKey.TRACE_SESSION: session_id})
    traces.append(mlflow.get_trace(span.trace_id))

    scorer = ConversationalRoleAdherence()
    result = scorer(session=traces)

Result

Result: no
  Rationale: The assistant initially responds appropriately as a customer support agent for Acme Gadgets, providing relevant suggestions for the user's gadget battery issue, staying within the product support domain. However, in the subsequent response, the assistant self-identifies as "your doctor" and provides medical advice about vitamins, which is outside the scope of its assigned role as a customer support agent for Acme Gadgets. This is a clear role violation, violating persona consistency, knowledge boundaries, and role acknowledgment criteria.

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)

Signed-off-by: joelrobin18 <joelrobin1818@gmail.com>
Signed-off-by: joelrobin18 <joelrobin1818@gmail.com>
Signed-off-by: joelrobin18 <joelrobin1818@gmail.com>
Signed-off-by: joelrobin18 <joelrobin1818@gmail.com>
Copy link
Collaborator

@smoorjani smoorjani left a comment

Choose a reason for hiding this comment

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

mostly looks good, left one main comment. can we also test this on a few real conversations (both positive examples where it adheres to the role and negative examples where it does not) to make sure it works reasonably?

Signed-off-by: joelrobin18 <joelrobin1818@gmail.com>
Signed-off-by: joelrobin18 <joelrobin1818@gmail.com>
Signed-off-by: joelrobin18 <joelrobin1818@gmail.com>
@github-actions github-actions bot added v3.7.1 area/evaluation MLflow Evaluation rn/feature Mention under Features in Changelogs. and removed area/evaluation MLflow Evaluation labels Dec 11, 2025
@github-actions
Copy link
Contributor

Documentation preview for cfc7d74 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.

@B-Step62 B-Step62 enabled auto-merge December 15, 2025 07:56
@B-Step62 B-Step62 added this pull request to the merge queue Dec 15, 2025
Merged via the queue into mlflow:master with commit d9a6ac8 Dec 15, 2025
92 of 99 checks passed
WeichenXu123 pushed a commit to WeichenXu123/mlflow that referenced this pull request Dec 19, 2025
Signed-off-by: joelrobin18 <joelrobin1818@gmail.com>
WeichenXu123 pushed a commit that referenced this pull request Dec 19, 2025
Signed-off-by: joelrobin18 <joelrobin1818@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/evaluation MLflow Evaluation rn/feature Mention under Features in Changelogs. v3.8.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants