async def test_rag_custom_system_prompt(self, mock_providers, mock_search_results):
        """Test RAG prompt construction with a custom system prompt."""
        class RAGPromptBuilder:
            def __init__(self, providers):
                self.providers = providers

            async def build_prompt(self, query, search_results, system_prompt_template_id=None):
                # Simple implementation that handles search results
                chunks = search_results.get("chunk_search_results", [])

                context = ""
                for i, chunk in enumerate(chunks):
                    # Format the chunk text
                    chunk_text = f"[{i+1}] {chunk.get('text', '')}"

                    context += chunk_text + "\n\n"

                # Get the custom system prompt template
                custom_prompt = "Custom system prompt with {{context}} and some instructions"
                if system_prompt_template_id:
                    # In a real implementation, this would fetch the template from a database
                    custom_prompt = f"Custom system prompt for {system_prompt_template_id} with {{{{context}}}}"

                # Replace the context placeholder with actual context
                system_content = custom_prompt.replace("{{context}}", context)

                return [
                    {"role": "system", "content": system_content},
                    {"role": "user", "content": query}
                ]

        # Create a custom system prompt template
        custom_prompt = "Custom system prompt with {{context}} and some instructions"

        # Create a RAG prompt builder
        builder = RAGPromptBuilder(providers=mock_providers)

        # Call the build method with a custom system prompt template ID
        query = "What did Aristotle say about ethics?"
        messages = await builder.build_prompt(
            query=query,
            search_results=mock_search_results,
            system_prompt_template_id="custom_template_id"
        )

        # Find the system message
        system_message = next((m for m in messages if m["role"] == "system"), None)

        # Check that the custom prompt was used
        assert "Custom system prompt" in system_message["content"], \
            "System message should use the custom prompt template"

        # Check that context was still injected
        assert "search result" in system_message["content"], \
            "Context should still be injected into custom prompt"
Test RAG prompt construction with a custom system prompt.
py/tests/unit/retrieval/test_rag_processing.py