Skip to content

Commit d6e1475

Browse files
committed
formatting
1 parent 8c0a1d0 commit d6e1475

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

src/app/endpoints/query.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,15 @@ def extract_referenced_documents_from_steps(steps: list) -> list[dict[str, str]]
7878
metadata_map: dict[str, dict[str, Any]] = {}
7979

8080
for step in steps:
81-
if getattr(step, "step_type", "") != "tool_execution" or not hasattr(step, "tool_responses"):
81+
if getattr(step, "step_type", "") != "tool_execution" or not hasattr(
82+
step, "tool_responses"
83+
):
8284
continue
8385

8486
for tool_response in getattr(step, "tool_responses", []) or []:
85-
if getattr(tool_response, "tool_name", "") != "knowledge_search" or not getattr(tool_response, "content", []):
87+
if getattr(
88+
tool_response, "tool_name", ""
89+
) != "knowledge_search" or not getattr(tool_response, "content", []):
8690
continue
8791

8892
_process_knowledge_search_content(tool_response, metadata_map)
@@ -472,7 +476,9 @@ async def retrieve_response( # pylint: disable=too-many-locals
472476
# Check for validation errors and extract referenced documents
473477
steps = getattr(response, "steps", [])
474478
for step in steps:
475-
if getattr(step, "step_type", "") == "shield_call" and getattr(step, "violation", False):
479+
if getattr(step, "step_type", "") == "shield_call" and getattr(
480+
step, "violation", False
481+
):
476482
# Metric for LLM validation errors
477483
metrics.llm_calls_validation_errors_total.inc()
478484

tests/unit/app/endpoints/test_query.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,14 +1594,14 @@ def test_process_knowledge_search_content_with_valid_metadata(mocker):
15941594
Content: Test content
15951595
Metadata: {'docs_url': 'https://example.com/doc1', 'title': 'Test Doc', 'document_id': 'doc-1'}
15961596
"""
1597-
1597+
15981598
tool_response = mocker.Mock()
15991599
tool_response.content = [text_content_item]
1600-
1600+
16011601
metadata_map = {}
1602-
1602+
16031603
_process_knowledge_search_content(tool_response, metadata_map)
1604-
1604+
16051605
# Verify metadata was correctly parsed and added
16061606
assert "doc-1" in metadata_map
16071607
assert metadata_map["doc-1"]["docs_url"] == "https://example.com/doc1"
@@ -1612,24 +1612,24 @@ def test_process_knowledge_search_content_with_valid_metadata(mocker):
16121612
def test_process_knowledge_search_content_with_invalid_metadata_syntax_error(mocker):
16131613
"""Test _process_knowledge_search_content handles SyntaxError from invalid metadata."""
16141614
mock_logger = mocker.patch("app.endpoints.query.logger")
1615-
1615+
16161616
# Mock tool response with invalid metadata (invalid Python syntax)
16171617
text_content_item = mocker.Mock()
16181618
text_content_item.text = """Result 1
16191619
Content: Test content
16201620
Metadata: {'docs_url': 'https://example.com/doc1' 'title': 'Test Doc', 'document_id': 'doc-1'}
16211621
""" # Missing comma between 'doc1' and 'title' - will cause SyntaxError
1622-
1622+
16231623
tool_response = mocker.Mock()
16241624
tool_response.content = [text_content_item]
1625-
1625+
16261626
metadata_map = {}
1627-
1627+
16281628
_process_knowledge_search_content(tool_response, metadata_map)
1629-
1629+
16301630
# Verify metadata_map remains empty due to exception
16311631
assert len(metadata_map) == 0
1632-
1632+
16331633
# Verify debug logging was called
16341634
mock_logger.debug.assert_called_once()
16351635
args = mock_logger.debug.call_args[0]
@@ -1639,24 +1639,24 @@ def test_process_knowledge_search_content_with_invalid_metadata_syntax_error(moc
16391639
def test_process_knowledge_search_content_with_invalid_metadata_value_error(mocker):
16401640
"""Test _process_knowledge_search_content handles ValueError from invalid metadata."""
16411641
mock_logger = mocker.patch("app.endpoints.query.logger")
1642-
1642+
16431643
# Mock tool response with invalid metadata containing complex expressions
16441644
text_content_item = mocker.Mock()
16451645
text_content_item.text = """Result 1
16461646
Content: Test content
16471647
Metadata: {func_call(): 'value', 'title': 'Test Doc', 'document_id': 'doc-1'}
16481648
""" # Function call in dict - will cause ValueError since it's not a literal
1649-
1649+
16501650
tool_response = mocker.Mock()
16511651
tool_response.content = [text_content_item]
1652-
1652+
16531653
metadata_map = {}
1654-
1654+
16551655
_process_knowledge_search_content(tool_response, metadata_map)
1656-
1656+
16571657
# Verify metadata_map remains empty due to exception
16581658
assert len(metadata_map) == 0
1659-
1659+
16601660
# Verify debug logging was called
16611661
mock_logger.debug.assert_called_once()
16621662
args = mock_logger.debug.call_args[0]
@@ -1666,24 +1666,24 @@ def test_process_knowledge_search_content_with_invalid_metadata_value_error(mock
16661666
def test_process_knowledge_search_content_with_non_dict_metadata(mocker):
16671667
"""Test _process_knowledge_search_content handles non-dict metadata gracefully."""
16681668
mock_logger = mocker.patch("app.endpoints.query.logger")
1669-
1669+
16701670
# Mock tool response with metadata that's not a dict
16711671
text_content_item = mocker.Mock()
16721672
text_content_item.text = """Result 1
16731673
Content: Test content
16741674
Metadata: "just a string"
16751675
"""
1676-
1676+
16771677
tool_response = mocker.Mock()
16781678
tool_response.content = [text_content_item]
1679-
1679+
16801680
metadata_map = {}
1681-
1681+
16821682
_process_knowledge_search_content(tool_response, metadata_map)
1683-
1683+
16841684
# Verify metadata_map remains empty (no document_id in string)
16851685
assert len(metadata_map) == 0
1686-
1686+
16871687
# No exception should be logged since string is valid literal
16881688
mock_logger.debug.assert_not_called()
16891689

@@ -1696,14 +1696,14 @@ def test_process_knowledge_search_content_with_metadata_missing_document_id(mock
16961696
Content: Test content
16971697
Metadata: {'docs_url': 'https://example.com/doc1', 'title': 'Test Doc'}
16981698
""" # No document_id field
1699-
1699+
17001700
tool_response = mocker.Mock()
17011701
tool_response.content = [text_content_item]
1702-
1702+
17031703
metadata_map = {}
1704-
1704+
17051705
_process_knowledge_search_content(tool_response, metadata_map)
1706-
1706+
17071707
# Verify metadata_map remains empty since document_id is missing
17081708
assert len(metadata_map) == 0
17091709

@@ -1712,13 +1712,13 @@ def test_process_knowledge_search_content_with_no_text_attribute(mocker):
17121712
"""Test _process_knowledge_search_content skips content items without text attribute."""
17131713
# Mock tool response with content item that has no text attribute
17141714
text_content_item = mocker.Mock(spec=[]) # spec=[] means no attributes
1715-
1715+
17161716
tool_response = mocker.Mock()
17171717
tool_response.content = [text_content_item]
1718-
1718+
17191719
metadata_map = {}
1720-
1720+
17211721
_process_knowledge_search_content(tool_response, metadata_map)
1722-
1722+
17231723
# Verify metadata_map remains empty since text attribute is missing
17241724
assert len(metadata_map) == 0

0 commit comments

Comments
 (0)