Can't make chatgpt produce a text with limited characters number


In a scenario, I scrape a webpage to extract the content and I ask chatgpt to make a summary shorter than 500 characters long.

I can’t manage to make it respect that character limit rule. I put: “write a short summary (maximum 500 characters long” of the text", and sometimes it works sometimes not.

Does someone know how to do that?

Hey @Pamela1
I made a scenario for this which is attached. Try this it will work for you.
blueprint (2).json (41.0 KB)

Sachin Shrivastava


According to OpenAI themselves, the main way to limit the characters of the completion, is by using the “Max tokens” setting. This is shared between the prompts and completion, so a bit of trial and error is required.

Here are the three ways the OpenAI developer article mention:

1. Reduce Max Tokens

The main way to control the length of your completion is with the max tokens setting. In the Playground, this setting is the “Response Length.” These requests can use up to 2,049 tokens, shared between prompt and completion.

2. Provide Instructions

Provide instructions to generate the desired output length, such as a specific number of items in a list. This works especially well with the instruct series.

3. Give Examples

Add examples of a specific length
The API is great at recognizing patterns and will consider the length of examples given when generating text. By providing an example, or multiple examples, with the desired output length, you can give needed context about the expected length.

For more information, see the original article linked above.


Thanks for the suggestion, but if after second summary the text is still over 500, it will break again. It is very little probable, but I would like to make the scenario robust.


I tried the max-token option, but there are two problems:

  1. the content I send to chatgpt to summarize is variable from a trigger to another, so I can’t know in advance how many tokens will be consumed by the input.
  2. if chatgpt reaches the max-token limit in the middle of a sentence, it will cut in the middle and make an unfinished sentence.

I will try the examples trick, thanks :slight_smile:

I am running some tests on the chatgpt playground:

If someone find the right prompt to to get a summary less than 500 characters long, 10 times in a row, please tell me!!!

After many test, it looks like chatgpt is not able to respect a “not more than xx characters” like instruction, because it goes writing and its like it can only check how much characters it used after it finishes. And sometimes it is more than permitted number of characters.

I concluded that this quantitative instruction have to go with a qualitative instruction like “make a super brief comment”.

“Make a comment not exceeding 300 characters” is very likely not to work, but “Make a super short comment no exceeding 300 characters” may work far better.

I also concluded that chatgpt respects better the character limit when asked to make a comment instead of a summary. With a comment, it can be more creative and better respect the limit. With a summary, it has less space for creativity, so it is more difficult for it to respect the limit.

If chatgpt can insert some creation and not only perform analysis, it will be able to better respect the characters limit. For instance “Comment must describe the content of the text” will hardly work, while “Comment must describe the content of the text, and must be supportive of Ukraine” will work a lot better.

I repeat: I am not a chatgpt pro, these are totally empirical conclusions and interpretations that may be erroneous.

I am still open to any successful prompt that can limit the number of characters of the output in 100% of the cases.


Short update: after some reading in chatgpt forum and some tests in chatgpt playground, it seems that chatgpt is better at counting words than characters.
So instead of establishing a character count limit, a word count limit is more likely to give good results.