def METHOD_NAME(self, prompt: Union[str, List[Dict[str, str]]]) -> Union[str, List[Dict[str, str]]]:
    """Make sure the length of the prompt and answer is within the max tokens limit of the model.
    If needed, truncate the prompt text so that it fits within the limit.
    :param prompt: Prompt text to be sent to the generative model.
    """
    if isinstance(prompt, str):
        messages = [{"role": "user", "content": prompt}]
    elif isinstance(prompt, list) and len(prompt) > 0 and isinstance(prompt[0], dict):
        messages = prompt
    # n_prompt_tokens = count_openai_tokens_messages(messages, self._tokenizer)
    n_prompt_tokens = len(messages)
    n_answer_tokens = self.max_length
    if (n_prompt_tokens + n_answer_tokens) <= self.max_tokens_limit:
        return prompt
    # TODO: support truncation as in _ensure_token_limit methods for other invocation layers
    raise ValueError(
        f"The prompt or the messages are too long ({n_prompt_tokens} tokens). "
        f"The length of the prompt or messages and the answer ({n_answer_tokens} tokens) should be within the max token limit ({self.max_tokens_limit} tokens). "
        f"Reduce the length of the prompt or messages."
    )