async def on_chain_end(
        self, outputs: dict[str, Any], **kwargs: dict[str, Any]
    ) -> None:
        """Run when chain ends running.

        Final output is streamed only if LLM cache is enabled.
        """
        if self.llm_cache_used or not self.streaming:
            if self.output_key in outputs:
                message = self._construct_message(
                    data=get_token_data(outputs[self.output_key], self.mode),
                    event=Events.COMPLETION,
                )
                await self.websocket.send_json(message)
            else:
                raise KeyError(f"missing outputs key: {self.output_key}")
Run when chain ends running.

        Final output is streamed only if LLM cache is enabled.
        
lanarky/adapters/langchain/callbacks.py