Prompt-Driven LLM Safeguarding via Directed Representation Optimization