# Variable response content with consistent format?

**URL:** <https://community.deeplearning.ai/t/variable-response-content-with-consistent-format/470810>\
**Category:** LangChain for LLM Application Development\
**Created:** [October 16, 2023, 12:36pm UTC](https://community.deeplearning.ai/t/variable-response-content-with-consistent-format/470810 "2023-10-16T12:36:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivar](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ivar/32/66930_2.png) [@ivar](https://community.deeplearning.ai/u/ivar)\
**Post date:** [October 16, 2023, 12:36pm UTC](https://community.deeplearning.ai/t/variable-response-content-with-consistent-format/470810/1 "2023-10-16T12:36:09Z")

</div>

Hi,

I have initialized my GPT model with temperature 0.7 because I need it to give variable responses for the content. However, when I do this it will occasionally provide a different output format (even though I have specified in the prompt that I want a specific output format). What I want is that the output format is always exactly the same, but the content of the response differs.

I was wondering how I can achieve this. Would the function “ChatPromptTemplate” be able to help with this?

Thank you!

---

<div class="post-metadata">

**Author:** ![leonardo.pabon](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/leonardo.pabon/32/67180_2.png) [@leonardo.pabon](https://community.deeplearning.ai/u/leonardo.pabon)\
**Post date:** [October 18, 2023, 12:38pm UTC](https://community.deeplearning.ai/t/variable-response-content-with-consistent-format/470810/2 "2023-10-18T12:38:41Z")

</div>

Have you tried in-context learning? Maybe providing in your prompt one or a few examples of task and completion in the desired format helps.

---

<div class="post-metadata">

**Author:** ![ivar](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ivar/32/66930_2.png) [@ivar](https://community.deeplearning.ai/u/ivar)\
**Post date:** [October 18, 2023, 1:21pm UTC](https://community.deeplearning.ai/t/variable-response-content-with-consistent-format/470810/3 "2023-10-18T13:21:37Z")

</div>

Hi Leonardo,

Thank you for your response. Yes, I tried that. It works most of the time but still sometimes it does not work (interestingly if I prompt the GPT with a highly creative persona, it perform way better than when I give it a very analytical persona).

How I solved it now, is that I just put the response call in a while loop and only save the response if the response matches the required format. This is a bit of a waste, money wise, but oh well.

---

<div class="post-metadata">

**Author:** ![leonardo.pabon](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/leonardo.pabon/32/67180_2.png) [@leonardo.pabon](https://community.deeplearning.ai/u/leonardo.pabon)\
**Post date:** [October 18, 2023, 2:15pm UTC](https://community.deeplearning.ai/t/variable-response-content-with-consistent-format/470810/4 "2023-10-18T14:15:36Z")

</div>

Hi Ivar,

It just occurred to me that you could also try the top-k and top-p parameters to avoid completions with too low a probability. This way, you have some creativity without an answer that is too far from normality. See if it works.
