Skip to content

Commit ccf1d82

Browse files
Prevent API keys from being saved as part of LLM metadata
Even when API keys are explicitly passed to the LLM, they should not be persisted as part of saved metadata in dialogs or persona json files. This prevents accidental exposure of sensitive credentials.
1 parent c1ff862 commit ccf1d82

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/sdialog/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ def get_llm_model(model_name: str,
455455
if tools:
456456
llm = llm.bind_tools(tools)
457457

458+
# Strip secrets from returned params (e.g., api_key, openai_api_key) for safe storage (e.g. in saved dialogs)
459+
llm_kwargs = {k: v for k, v in llm_kwargs.items() if "api_key" not in k.lower()}
460+
458461
return llm if not return_model_params else (llm, llm_kwargs)
459462

460463

0 commit comments

Comments
 (0)