Improve Prompt for Better Results

I’m working on a project in which an Admin can upload a policy file.

On Client side, user will select the template and generate new Document that similar (Same style, font, size) to template. User can also upload a pdf file and on backend the file is parsed and text is given through prompt.

Currently I’m using given below prompt for generating a new document.

` Please utilize the document identified by ID: *${uploadedFileId}*, applying it as a template of the type ${selectedTemplate?.type || "Annual Review Template"}. Your tasks are outlined as follows
            1. Conduct a thorough, word-by-word analysis to fully grasp the document's content.
            2. Upon achieving a comprehensive understanding, you are to update the document in accordance with the given user prompts.

            User Instructions for Updates:
            - Title: ${data?.title} (Should be same font size and style)
            - Company Name: ${data?.companyName} (Replace it wherever found throughout the document)
            - Email: ${data?.email} (Replace it wherever found throughout the document)

            ${data?.file && user_inputs ? `-${user_inputs}` : ''}
            Wherever it seems appropriate within the document, these user instructions should be incorporated or used to replace existing information.

            It is essential to retain the original design, style, font, and format of the document.

            Note: The document is provided in the ${fileExt?.includes('.pdf') ? 'docx' : selectedTemplate?.file?.ext} format. You are tasked with generating a new document in the same ${fileExt?.includes('.pdf') ? 'docx' : selectedTemplate?.file?.ext} format, ensuring that the format, design, style, and font are consistently maintained and newly file named should be as ${removeFileExtension(fileName) + '_user_' + data?.user}
            
            Additionally, generate a 50 word description of the newly generated document in a separate message as follows:
            Description: "start description here". Just write the description based on the information found within the document only. Please don't mention information about the title, filename and company of the document.
  

This prompt does not work well. Need expert suggestions how can I improve this prompt for getting better results through openai assistant api.

Currently Behave: It did not replace the possible changes in the file and does not maintain the style of template.

Heya.

That’s a pretty complicated prompt. A one-shot example here would help it a lot, I bet. Costs more, but output should be better. In fact, once you have it working in GPT-4o, you might be able to get it to work with gpt-3.5-turbo with the examples…

1 Like

Hey! I’m not even a GPT but a human yet I had to read your prompt a couple of times and still unsure what you are trying to achieve. :slightly_smiling_face: Is all you want the model to do replace a couple of placeholders in your file? This would generally be something that you should be able to do with some simple string manipulations without AI, if I’m not missing any extra complexity.

I also don’t know how well assistants are able to work with formatted content in documents.

Finally, your prompt is pretty hard to read, even to humans, which makes it less likely to be followed by the model. Try to improve the structure of your prompt (e.g., top-down, why, what, how, separate logic from data), use clearer language (e.g., “utilize the document” → “transform/adjust”?, “user instructions for updates” → “replace the following placeholders”?). Why do you ask it to “conduct a thorough analysis”? I’m pretty sure ChatGPT or some custom GPTs will be able to help you improve your prompt. :slightly_smiling_face:

I think you are confusing the AI by asking it to do too much, most of which is not clearly defined.

If a human cannot understand what you are trying to achieve then even AI may struggle.

Maybe make your goals more explicit in natural language - or you could consider breaking the prompt into a chain of smaller prompts, each with a specific function/goal. This will enable you to refine and improve each step of the process.

Good luck!

1 Like

Tips:

  • Start by setting context for what the AI’s meant to be an expert in for your task.
  • Keep the instruction linear and group all exceptions together.
  • Ask the AI to rewrite the prompt for you.

For example:

You are an expert at (file conversion?), taking files in (x format) and producing them in (y format)

(x format)=

  • company
  • name

(y format)=

  • contact = name@company

Perform the conversion using the following steps:

  1. Extract fields from x-format

  2. Make some calculations
    If this, then that
    If this, then that
    If this, then that

  3. Write y-format

  4. Write a 50 word description.

Try this


Effectuate the following:

1. Conduct a thorough, word-by-word analysis of the document identified by ID: *${uploadedFileId}* to fully grasp its content.
   
2. Update the document based on the given user inputs while retaining the original design, style, font, and format.

**User Instructions for Updates:**
   - **Title:** ${data?.title} (Maintain same font size and style)
   - **Company Name:** ${data?.companyName} (Replace wherever found in the document)
   - **Email:** ${data?.email} (Replace wherever found in the document)
   - **Additional User Inputs:** ${data?.file ? user_inputs : ''}

3. Ensure that the format, design, style, and font are consistently maintained. Produce the updated document in the same ${fileExt?.includes('.pdf') ? 'docx' : selectedTemplate?.file?.ext} format. The new file name should be: ${removeFileExtension(fileName) + '_user_' + data?.user}.

4. Generate a 50-word description of the newly updated document in a separate message based solely on the content within the document. Do not mention the title, filename, or company name.

**Clarifying Notes:**
   - Follow the exact update instructions provided by the user.
   - Ensure every modification adheres strictly to the original format specifics.

If any step or instruction needs further detail or there are uncertainties, refer back for clarification.


1 Like

That makes sense, but the issue is that the template uploaded by the admin is completely unpredictable. We don’t know what will be in the document or what changes the end user will want in the template. Therefore, I believe it’s essential to focus strictly on the user instructions. The AI should identify these instructions in the document, replace them accordingly, and generate a new document with a similar design and font.


Set Clear Context: Clearly define the task and the expertise required at the beginning of the prompt.
Break Down Instructions: Separate the task into clear, manageable steps.
Simplify Language: Use straightforward and unambiguous language.
Include Examples: Provide examples of the input and expected output to help the AI understand the task better.
Explain in Detail: Describe what content is in each file and what you expect for the output.


Context: You are an expert in document formatting and text replacement. Your task is to update a given document based on specific user instructions while maintaining the original design, style, font, and format.

Task Instructions:

  1. Analyze the Document: Review the document identified by ID: ${uploadedFileId} thoroughly to understand its content and structure.

  2. User Instructions for Updates:

    • Title: Replace the title with ${data?.title}. Ensure the new title has the same font size and style as the original.
    • Company Name: Replace every occurrence of the company name with ${data?.companyName}.
    • Email: Replace every occurrence of the email with ${data?.email}.
    • Additional Inputs: If there are additional user inputs, integrate ${user_inputs} at appropriate locations within the document.
  3. Maintain Original Format: Ensure that the updated document retains the original design, style, font, and format.

  4. Output Format: Generate the updated document in the same format as the original (either .docx or the format specified in ${selectedTemplate?.file?.ext}). Name the new file as ${removeFileExtension(fileName) + '_user_' + data?.user}.

  5. Generate Description: Create a 50-word description of the updated document based solely on its content. Do not include details about the title, filename, or company name.

Example:

  • Original Title: “Annual Report 2023”
  • New Title: “${data?.title}” (e.g., “Quarterly Review 2024” in the same font and style)
  • Original Company Name: “ABC Corp”
  • New Company Name: “${data?.companyName}” (replace “ABC Corp” with “XYZ Ltd” throughout the document)
  • Original Email: “contact@abccorp.com
  • New Email: “${data?.email}” (replace “contact@abccorp.com” with “info@xyzltd.com”)

Clarifying Notes:

  • Focus strictly on the user instructions for replacements and updates.
  • Ensure that every modification adheres strictly to the original format specifics.

Explain in Detail:

  • File Content: For each file, explain what type of content it contains (e.g., policy documents, reports, reviews) and the purpose of the document. Provide a brief overview of the structure (e.g., headers, footers, sections).
  • Expected Output: Describe what you expect the updated document to look like. For instance, if it’s a policy document, the title should reflect the new policy name, the company name should be updated throughout, and any other specified changes should be seamlessly integrated.
  • Granulate Tasks: Break down each task into smaller, more specific steps. For example:
    • Step 1: Identify and replace the title.
    • Step 2: Search and replace the company name throughout the document.
    • Step 3: Search and replace the email throughout the document.
    • Step 4: Integrate any additional inputs as specified by the user.
    • Step 5: Ensure all replacements match the original font, style, and formatting.
    • Step 6: Generate the new file in the specified format and name it accordingly.

Granulating each task and helping the AI ‘see’ the output you envision will lead to success. The more detailed and specific your instructions, the better the AI will perform.

2 Likes

I don’t think that kind of approach would help specially since we don’t know OP’s use case. Or even model, for that matter. So a gigantic block of text pinpointing a use-case, not only burns tokens, it’s very limiting for the model’s “ideaspace”. If you want a bot like the old days (more a script) its okay but in LLM matters one should exploit or at least enable its patternrecog and pathfinding algos (more linkages from desparate ideas leading to better generalization)