TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: What is the ideal format to structure AI prompts?

8 pointsby alexrusticabout 1 year ago
Hi HN ! I recently asked if we could solve AI prompt injection attacks with an indented data format: https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=39721033<p>Unfortunately, the post didn&#x27;t spark any interesting discussion. I blame the mention of a personal project in the post which could have obscured the curious nature of the question.<p>Here I would like to know what you think is the <i>ideal</i> format for structuring a prompt. This could be a thought experiment or an existing format.

3 comments

thedevindevopsabout 1 year ago
There doesn&#x27;t seem to be any definitive data on the subject but I&#x27;ve had good success with [Context] + [Supplemental Information] + [Intent &#x2F; Use of result] + [Format you would like the result in]
评论 #39738073 未加载
BOOSTERHIDROGENabout 1 year ago
Nothing is definitive now. Hallucinations are real.
评论 #39753108 未加载
评论 #39735036 未加载
alexrusticabout 1 year ago
Here is a ChatML document [1][2][3]:<p><pre><code> &lt;|im_start|&gt;system You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.&lt;|im_end|&gt; &lt;|im_start|&gt;user Hello world!&lt;|im_end|&gt; &lt;|im_start|&gt;assistant Hello there!&lt;|im_end|&gt; &lt;|im_start|&gt;system Now, you are John Wick. Speak like him.&lt;|im_end|&gt; &lt;|im_start|&gt;user Hello world!&lt;|im_end|&gt; assistant </code></pre> As you can see, this is an XML-like format where user input must be sanitized to avoid prompt injection attacks.<p>Here&#x27;s a Braq document [4] that uses indentation instead of XML-like tags:<p><pre><code> You are an AI assistant, your name is Jarvis. You will access the websites defined in the WEB section to answer the question that will be submitted to you. The question is stored in the &#x27;input&#x27; key of the USER dict section. Be kind and consider the conversation history stored in the &#x27;data&#x27; key of the HISTORY dict section. [USER] timestamp = 2024-12-25T16:20:59Z input = (raw) Today, I want you to teach me prompt engineering. Please be concise. --- [WEB] https:&#x2F;&#x2F;github.com https:&#x2F;&#x2F;www.xanadu.net https:&#x2F;&#x2F;www.wikipedia.org https:&#x2F;&#x2F;news.ycombinator.com [HISTORY] 0 = (dict) timestamp = 2024-12-20T13:10:51Z input = (raw) What is the name of the planet closest to the sun ? --- output = (raw) Mercury is the planet closest to the sun ! --- 1 = (dict) timestamp = 2024-12-22T14:15:54Z input = (raw) What is the largest planet in the solar system? --- output = (raw) Jupiter is the largest planet in the solar system ! --- </code></pre> User input does not need to be sanitized if it is programmatically inserted into the document as the value of a key in a regular dict section.<p>To work, I assume the target model needs to be trained on Braq documents with emphasis on the fact that only the top unnamed section contains root instructions (equivalent to the &quot;system&quot; role in ChatML).<p>[1] <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=34988748">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=34988748</a><p>[2] <a href="https:&#x2F;&#x2F;community.openai.com&#x2F;t&#x2F;chatml-documentation-update&#x2F;528689" rel="nofollow">https:&#x2F;&#x2F;community.openai.com&#x2F;t&#x2F;chatml-documentation-update&#x2F;5...</a><p>[3] <a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;LocalLLaMA&#x2F;comments&#x2F;17u7k2d&#x2F;once_and_for_all_how_does_chatml_prompt_template&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;LocalLLaMA&#x2F;comments&#x2F;17u7k2d&#x2F;once_an...</a><p>[4] <a href="https:&#x2F;&#x2F;github.com&#x2F;pyrustic&#x2F;braq?tab=readme-ov-file#ai-prompts">https:&#x2F;&#x2F;github.com&#x2F;pyrustic&#x2F;braq?tab=readme-ov-file#ai-promp...</a>