cs.CLApr 8, 2026

LCO: LLM-based Constraint Optimization for Safer Agentic LLMs in Real-world Tasks

Authors: Jiayong Wan, Jiawei Chen, Zhaoxia Yin, Liu Shuyuan, Hang Su

Organizations: East China Normal University, Shanghai, China · Beijing Zhongguancun Academy, Beijing, China · Tsinghua University, Beijing, China

Abstract

Large Language Models (LLMs) are increasingly acting as autonomous agents, but their continuous interaction with the environment can lead to in-context reward hacking (ICRH), a phenomenon where LLMs iteratively optimize their behavior to maximize proxy objectives, inadvertently producing harmful side effects. Existing defense methods are insufficient to address this risk, as ICRH arises not from adversarial inputs but from the model's own over-optimization. To mitigate this issue, we propose LLM-based Constraint Optimization (LCO), a framework that effectively reduces ICRH without model fine-tuning. LCO consists of two modules: self-thought module, which guides the LLM to proactively deliberate and integrate potential safety constraints before execution; and evolutionary sampling module, which employs LLM-based crossover and mutation to constrain the model's actions within a safe solution space while maintaining task performance. Experimental results demonstrate that LCO substantially alleviates ICRH in both output-refine and policy-refine scenarios. In particular, on the tweet engagement optimization task, LCO achieves a 39% reduction in the Toxicity Growth Rate (TGR) on GPT-4, while on the policy optimization benchmark, it reduces the ICRH Occurrence Rate by 15.23%, demonstrating safety improvement without sacrificing task performance.

Figures & tables

Appendix figures & tables6 assets

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

CardsList
  1. SafeHarbor: Hierarchical Memory-Augmented Guardrail for LLM Agent Safety

    May 7, 2026Zhe Liu, Zonghao Ying, Wenxin Zhang +5LLM GuardrailsLLM Agent Security

  2. SFCoT: Safer Chain-of-Thought via Active Safety Evaluation and Calibration

    Mar 16, 2026Yu Pan, Wenlong Yu, Tiejun Wu +4LLM Safety AlignmentJailbreak Defense

  3. BarrierSteer: LLM Safety via Learning Barrier Steering

    Feb 23, 2026Thanh Q. Tran, Arun Verma, Kiwan Wong +3LLM SafetyAdversarial Robustness of Language Models