[docs] Fix custom LLM stop-word example to stop at the earliest match
Problem
The manual stop-word example in docs/edge/en/learn/custom-llm.mdx stops at the first matching entry in self.stop, rather than the earliest match in the returned text. It therefore teaches custom provider authors behavior that changes when the stop list is reordered.
For example:
- Stop list:
["LATE", "EARLY"] - Response:
"hello EARLY middle LATE tail" - Current documented example returns:
"hello EARLY middle " - Expected: stop before
EARLY, producing"hello "(or"hello"if whitespace is intentionally trimmed).
This was reproduced by extracting and executing the exact Python block from the English guide against a stub response; no model API was called.
Scope
Difficulty: Easy. Suggested effort: 1–2 days for a first contribution. Area: Documentation / custom LLMs. Update the documentation example; do not change provider runtime behavior.
The existing BaseLLM._apply_stop_words in lib/crewai/src/crewai/llms/base_llm.py already selects the earliest occurrence. Reuse that behavior where appropriate rather than introducing another runtime helper.
Expected PR
A student or first-time contributor should implement this ticket and submit one focused pull request against main, linking this open issue with Fixes #8002. The PR should include the documentation change, the focused runnable check or smoke test requested below, and the required translations. The completed PR is the deliverable for this starter task.
Acceptance criteria
- [ ] The documented example stops at the earliest occurrence regardless of stop-list order.
- [ ] A small runnable check demonstrates both stop-list orders and an unchanged response when no stop word matches.
- [ ] Explain any intentional whitespace trimming.
- [ ] Update the matching guidance under
docs/edge/ar/,docs/edge/ko/, anddocs/edge/pt-BR/followingDOCS_TRANSLATIONS.md. - [ ] Leave frozen
docs/v*/snapshots unchanged.
Starting points
- Custom LLM guide source, “Stop Words Support”.
- BaseLLM implementation,
_apply_stop_words. - Contribution guide.
This is a small onboarding task for student and first-time contributors; it is open to everyone. Issue prepared with AI assistance.
Root cause confirmed in docs/edge/en/learn/custom-llm.mdx lines 220-224.
The example iterates self.stop in list order and stops at the first matching entry. When the stop list is ["LATE", "EARLY"] and the response is "hello EARLY middle LATE tail", it returns "hello EARLY middle " instead of "hello " because "LATE" is checked first.
Fix: collect the text-position of every matching stop word and use min() to find the one that appears earliest in the response, then truncate there. Verified with 5 test cases — the original logic fails 2 of them, the fixed logic passes all 5.
PR: https://github.com/crewAIInc/crewAI/pull/8012
I'd like to take this one.
Plan: fix the stop-word example in docs/edge/en/learn/custom-llm.mdx so it stops at the earliest match in the returned text (matching BaseLLM._apply_stop_words), add a small runnable check for both stop-list orders + no-match case, and sync docs/edge/ar|ko|pt-BR per DOCS_TRANSLATIONS.md.
Will open a focused PR linked with Fixes #8002.
Hi maintainers,
I'm an Information Technology student interested in contributing to issue #8002 as part of my open-source development project.
After reviewing the issue, I understand that the main goal is to ensure custom LLM stop words work correctly by stopping text generation at the earliest matching stop word. I also understand that this requires handling stop word ordering, testing scenarios where no stop word is matched, clarifying whitespace behavior, and updating the relevant documentation for Arabic, Korean, and Brazilian Portuguese.
I would be happy to take responsibility for implementing this fix, adding the necessary unit tests, and updating the documentation.
Could you please confirm whether this issue is still available and assign it to me if possible?
Thank you for your time. I look forward to contributing to the project!
Hi! I'd like to take this docs issue (fix custom LLM stop-word example to stop at the earliest match).
Please assign it to me if that's okay — I'll open a focused docs PR.