@@ -356,6 +356,38 @@ def test_separate_instances_warn_independently() -> None:
356356 assert len (deprecation_warnings ) == 2 # noqa: S101
357357
358358
359+ def test_init_backward_compatibility_with_llm_response_param () -> None :
360+ """Test that __init__ accepts both llm_response and _llm_response parameters."""
361+ mock_llm_response = _create_mock_chat_completion ()
362+ guardrail_results = _create_mock_guardrail_results ()
363+
364+ # Old parameter name should still work (backward compatibility)
365+ response_old = GuardrailsResponse (
366+ llm_response = mock_llm_response ,
367+ guardrail_results = guardrail_results ,
368+ )
369+ assert response_old .id == "chatcmpl-123" # noqa: S101
370+
371+ # New parameter name should work
372+ response_new = GuardrailsResponse (
373+ _llm_response = mock_llm_response ,
374+ guardrail_results = guardrail_results ,
375+ )
376+ assert response_new .id == "chatcmpl-123" # noqa: S101
377+
378+ # Both should raise TypeError
379+ with pytest .raises (TypeError , match = "Cannot specify both" ):
380+ GuardrailsResponse (
381+ llm_response = mock_llm_response ,
382+ _llm_response = mock_llm_response ,
383+ guardrail_results = guardrail_results ,
384+ )
385+
386+ # Neither should raise TypeError
387+ with pytest .raises (TypeError , match = "Must specify either" ):
388+ GuardrailsResponse (guardrail_results = guardrail_results )
389+
390+
359391def test_dir_includes_delegated_attributes () -> None :
360392 """Test that dir() includes attributes from the underlying llm_response."""
361393 mock_llm_response = _create_mock_chat_completion ()
0 commit comments