mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix(logging): treat an empty prompt_id as no prompt in manager dispatch
should_run_prompt_management_hooks gates on `if prompt_id`, so an empty
string reaches dispatch as a call that names no prompt. Dispatch gated on
`prompt_id is None`, so the empty string skipped the guard, a registered
prompt manager was selected, and the cache_control hook behind it in the
chain never ran.
4829bb3a15 fixed the prompt-less case. This narrows the remaining gap so
both sites read a blank prompt_id the same way.
This commit is contained in:
parent
7419a536ad
commit
bcc5c906f7
2 changed files with 32 additions and 1 deletions
|
|
@ -1157,7 +1157,7 @@ class Logging(LiteLLMLoggingBaseClass):
|
|||
)
|
||||
|
||||
for logger in prompt_management_loggers:
|
||||
if prompt_id is None and not self._prompt_manager_runs_without_prompt_id(
|
||||
if not prompt_id and not self._prompt_manager_runs_without_prompt_id(
|
||||
logger=logger,
|
||||
prompt_spec=prompt_spec,
|
||||
dynamic_callback_params=dynamic_callback_params,
|
||||
|
|
|
|||
|
|
@ -7004,3 +7004,34 @@ def test_get_additional_headers_survives_a_thread_growing_headers_mid_copy():
|
|||
assert copied["llm_provider-x-custom-1999"] == "1999"
|
||||
|
||||
_run_while_a_thread_grows(headers, read, reads=300)
|
||||
|
||||
|
||||
def test_prompt_hooks_skip_prompt_managers_when_prompt_id_is_empty(logging_obj, tmp_path, monkeypatch):
|
||||
"""
|
||||
`should_run_prompt_management_hooks` gates on `if prompt_id`, so an empty string reaches
|
||||
dispatch as a call that names no prompt. Dispatch gated on `prompt_id is None`, so it
|
||||
handed the call to the dotprompt manager anyway and the cache_control hook never ran.
|
||||
"""
|
||||
from litellm.integrations.dotprompt.dotprompt_manager import DotpromptManager
|
||||
|
||||
(tmp_path / "stem.prompt").write_text("---\nmodel: claude-opus-4-5\n---\nyou are a stem tutor\n")
|
||||
dotprompt_manager = DotpromptManager(prompt_directory=str(tmp_path))
|
||||
monkeypatch.setattr(litellm, "callbacks", [dotprompt_manager])
|
||||
|
||||
cache_control_params = {"cache_control_injection_points": [{"role": "system", "location": "message"}]}
|
||||
messages = [
|
||||
{"role": "system", "content": "you are a stem tutor"},
|
||||
{"role": "user", "content": "hi"},
|
||||
]
|
||||
|
||||
assert logging_obj.should_run_prompt_management_hooks(prompt_id="", non_default_params=cache_control_params)
|
||||
|
||||
_, compiled_messages, _ = logging_obj.get_chat_completion_prompt(
|
||||
model="claude-opus-4-5",
|
||||
messages=messages,
|
||||
non_default_params=cache_control_params,
|
||||
prompt_variables=None,
|
||||
prompt_id="",
|
||||
)
|
||||
|
||||
assert compiled_messages[0]["cache_control"] == {"type": "ephemeral"}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue