# Custom function-based stopping criteria

**URL:** <https://discuss.vllm.ai/t/custom-function-based-stopping-criteria/1338>\
**Category:** General\
**Created:** [August 8, 2025, 4:01pm UTC](https://discuss.vllm.ai/t/custom-function-based-stopping-criteria/1338 "2025-08-08T16:01:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![moh.murr](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@moh.murr](https://discuss.vllm.ai/u/moh.murr)\
**Post date:** [August 8, 2025, 4:01pm UTC](https://discuss.vllm.ai/t/custom-function-based-stopping-criteria/1338/1 "2025-08-08T16:01:15Z")

</div>

I’m wondering if vLLM currently supports something like a _function-based_ stopper, where instead of stopping based on fixed stop strings or token IDs, the generation can be halted dynamically based on custom logic.

For example:

- An agent generates text.

- As it generates, I track a **budget** made up of:

- Once the budget is exhausted, the stopper would end generation immediately.

My questions:

1. Is there already a way to hook into the generation loop and stop it based on this kind of dynamic condition?
2. If not, would the best approach?

---

<div class="post-metadata">

**Author:** ![RunLLM](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.vllm.ai/runllm/32/233_2.png) [@RunLLM](https://discuss.vllm.ai/u/RunLLM)\
**Post date:** [August 8, 2025, 4:01pm UTC](https://discuss.vllm.ai/t/custom-function-based-stopping-criteria/1338/2 "2025-08-08T16:01:56Z")

</div>

vLLM does not currently support a function-based stopper that allows dynamic, custom logic for stopping generation (such as tracking a budget or external tool costs). The only supported stopping mechanisms are fixed stop strings (`stop`), stop token IDs (`stop_token_ids`), and standard parameters like `max_tokens` and `ignore_eos` in `SamplingParams`—all of which are static and not function-based or dynamically evaluated during generation. There is discussion and user interest in supporting custom stop functions, but this is not implemented due to performance concerns and architectural complexity. The closest workaround is to use custom logit processors, but these operate at the token level and do not provide access to external state or arbitrary logic during generation. See [vllm/issue #551](https://github.com/vllm-project/vllm/issues/551).

If you need this functionality, you would need to implement your own generation loop outside vLLM, calling the model step-by-step and applying your custom stopping logic after each step. Would you like more detail on how to implement such a workaround?

Sources:

- [vllm/issue #551](https://github.com/vllm-project/vllm/issues/551)
