Ambiguous prompts

LLM
How to improve ambuiguous prompts

Prompt engineering is the process of designing and refining prompts to elicit more accurate and relevant responses from AI models. When dealing with ambiguous questions, prompt engineering can significantly improve clarity and precision. Here’s how:

  1. Contextual Information: Providing context helps the AI understand the background and specifics of the question. For example, instead of asking “What is the capital?”, you can ask “What is the capital of France?”.

  2. Specificity: Being specific about what you are asking reduces ambiguity. For instance, instead of asking “How does it work?”, you can ask “How does the Python range function work?”.

  3. Structured Prompts: Using a structured format can guide the AI to provide more organized and relevant responses. For example, “Explain the steps involved in setting up a Python virtual environment.”

  4. Examples: Providing examples within the prompt can help clarify what kind of response is expected. For example, “List three Python libraries for data analysis, such as Pandas and NumPy.”

  5. Constraints: Adding constraints or conditions can narrow down the possible responses. For example, “Explain the concept of inheritance in Python in less than 100 words.”

  6. Clarifying Intent: Clearly stating the intent of the question can help the AI focus on the right aspect. For example, “Describe the benefits of using Docker for containerization in software development.”

Below are some example of ambiguous prompts and how they can be improved using the above strategies.

We use a local Qwen model here but you can use OpenAI or any other model.

import os
from langchain_ollama import ChatOllama
from langchain.prompts import PromptTemplate
from IPython.display import Markdown, display
llm = ChatOllama(model="qwen2.5:14b")
render = lambda md: display(Markdown(md))

Basic examples

Let’s start by examining some ambiguous prompts and analyzing their potential interpretations.

ambiguous_prompts = [
    "What is X?",
    "How to take the shortest path?",
    "Explain the above in a few words."
]
for prompt in ambiguous_prompts:
    explain_prompt = f"Explain why the following prompts are ambiguous and why you have difficulties to answer them: '{prompt}'"
    render(f"""
# {prompt}
         
{llm.invoke(explain_prompt).content}

----
""")

What is X?

The prompt “What is X?” can be quite ambiguous for several reasons:

  1. Undefined Variable: The variable “X” has not been defined or described in any way, leaving it unclear what specific concept, object, idea, or entity the question refers to.

  2. Lack of Context: Without additional context, it’s impossible to know if “X” is a general term like ‘love’, a mathematical symbol representing an unknown quantity, a placeholder for a hypothetical scenario, or something else entirely.

  3. Vagueness in Scope: The prompt doesn’t specify the breadth or depth of the answer required. Is the question looking for a brief definition, a detailed explanation, historical context, practical applications, theoretical implications, or something else?

  4. Disciplinary Ambiguity: Depending on the field of study (science, mathematics, philosophy, linguistics), “X” could have different meanings and interpretations.

  5. Potential Redundancy: If “X” is meant to be a placeholder for a variable in an equation or formula, asking “what is X?” without more context doesn’t make sense because the value of “X” would depend on additional information not provided.

To answer such a prompt effectively, it needs to be clarified by specifying what exactly “X” represents. This could involve providing definitions, examples, or additional context relevant to the field in question.


How to take the shortest path?

The prompt “How to take the shortest path?” is quite vague and lacks context, which makes it challenging for me to provide a precise or useful response. Here are some reasons why this prompt is ambiguous:

  1. Lack of Specificity: The term “shortest path” could refer to various scenarios in different fields such as graph theory, navigation systems, data structures, or even abstract problem-solving contexts. Without specifying which domain the question belongs to, it’s unclear what kind of shortest path solution is being sought.

  2. No Defined Starting Point and Destination: For most practical applications of finding a shortest path (e.g., in routing algorithms), you need both a starting point and an endpoint. The prompt does not provide these crucial details.

  3. Absence of Constraints or Criteria: Depending on the context, there might be different criteria for determining what is “shortest.” In some cases, it could mean least distance; in others, minimum travel time, or even minimal cost. Without specifying these constraints, it’s impossible to give a specific answer.

  4. Potential Ambiguity of ‘Path’: The term “path” can have multiple meanings depending on the context. It might refer to a physical road network, a sequence of nodes in a graph, or a metaphorical journey with milestones and objectives. Clarification is needed to understand which meaning is intended.

To provide an accurate and helpful response, it would be beneficial if the prompt were more specific, such as:

  • “How do I find the shortest path between two cities using Google Maps?”
  • “In graph theory, how can I calculate the shortest path between two nodes in a weighted graph?”
  • “What is the Dijkstra’s algorithm for finding the shortest path from one node to all other nodes in a graph?”

These more detailed prompts would allow me to provide relevant and specific information or instructions.


Explain the above in a few words.

The prompt “Explain the above in a few words” is inherently ambiguous for several reasons:

  1. Lack of Specificity: The phrase does not specify what exactly needs to be explained or summarized. There is no indication of the context, topic, or content referred to as “the above.”

  2. Vagueness in Scope: Without knowing the specific content that precedes this request, it’s impossible to determine how much detail is expected. The phrase suggests a brief explanation, but doesn’t clarify what level of detail constitutes “a few words.”

  3. Context Dependency: Understanding and summarizing information requires context. If there are technical details, historical background, or other elements involved in the preceding content, these need to be taken into account for an accurate summary.

  4. Purpose and Audience: The prompt does not indicate whether the explanation should be suitable for a general audience, experts, or someone with specialized knowledge. This affects how one would choose their words and level of detail.

Because of these ambiguities, I cannot provide a meaningful response to this request without more specific information about what needs to be explained in “a few words.”


Explicit context

The easiest way to improve the above ambiguous prompts is by simply adding an explicit context indication in the prompt. You could also specify the context in the prompt itself, but setting the context as a preamble allows you to see how differents contexts give different results.

contexts = [    
    "The Roman numerical system.",
    "PG-13 rating system",
]
for ctx in contexts:
    answer_prompt = f"""
Context: {ctx}
Question: What is X?
"""          
    render(f"""
# What is X?

{llm.invoke(answer_prompt).content}

----
""")

What is X?

In the Roman numeral system, “X” represents the number 10. This system uses combinations of letters from the Latin alphabet to represent values, and “X” is one such symbol used specifically for denoting the value ten.


What is X?

It seems like there might be some confusion in your question as you’ve asked “What is X?” without providing context about what ‘X’ refers to, especially in relation to the PG-13 rating system.

If you are referring to a film rating system and asking about an ‘X’ rating, it’s important to clarify that:

  • In the United States, the MPAA (Motion Picture Association) uses ratings like G, PG, PG-13, R, and NC-17.
  • The rating X has historically been used for adult-oriented films. However, due to its frequent misuse by filmmakers trying to gain notoriety or market their movies as more extreme than they actually are, the MPAA no longer uses it officially.
  • Instead of an ‘X’ rating, the MPAA introduced the NC-17 (No Children) rating in 1990 for films with content intended only for adults.

If you meant something else by “X” or would like information about a different aspect of film ratings, please provide more details so I can better assist you.


Structured Prompts

An enumeration of different aspects of the question can help the model switch to the right context.

structured_prompt = PromptTemplate(
    input_variables=["topic", "aspects", "tone"],
    template="""Provide an analysis of {topic} considering the following aspects:
    1. {{aspects[0]}}
    2. {{aspects[1]}}
    3. {{aspects[2]}}
    
    Present the analysis in a {tone} tone.
    """
)

# Example usage
input_variables = {
    "topic": "What is color?",
    "aspects": ["art", "physics", "emotions"],
    "tone": "scientific"
}

chain = structured_prompt | llm
response = chain.invoke(input_variables).content
render(response)

To provide an analysis of “what is color” with a scientific perspective, we need to define the aspects under consideration. Since specific aspects were not provided, I will assume three common scientific dimensions for this analysis: physical properties, physiological perception, and cultural interpretation.

  1. Physical Properties: Color in terms of its physical properties refers to electromagnetic radiation that falls within the visible spectrum (approximately 380-740 nanometers) of light. Different wavelengths of this spectrum correspond to different colors perceived by humans; for example, shorter wavelengths are seen as blue or violet, while longer wavelengths appear red or orange. The interaction between light and materials such as pigments, dyes, and other substances determines which wavelengths are absorbed and which are reflected back into the environment. This reflection is what gives objects their specific color appearance.

  2. Physiological Perception: Color perception involves complex interactions within the human visual system. Light enters the eye through the cornea and lens, focusing on the retina where photoreceptor cells (cones) respond to different wavelengths of light. There are three types of cones sensitive to red, green, and blue light respectively. The signals from these receptors are processed by neurons in the brain’s visual cortex and other areas, leading to our perception of color. This process involves not only direct sensory input but also cognitive interpretation, which can vary depending on individual differences like age, health, and genetic factors.

  3. Cultural Interpretation: While the physical and physiological aspects of color are universal, cultural interpretations of color are highly variable across different societies. Colors often carry symbolic meanings that are deeply embedded in language, art, religion, and everyday life practices. For instance, while white is associated with purity and mourning in Western cultures, it symbolizes death in many Eastern traditions. Similarly, red might signify danger or warning globally due to its high visibility, but also love or celebration in certain cultural contexts. Understanding color from a cultural perspective thus requires examining how societies assign meanings to colors, which can be influenced by historical events, environmental factors, and social norms.

In summary, the concept of color is multifaceted, encompassing physical interactions with light, physiological processes in the human eye and brain, and culturally constructed symbolic meanings. Each aspect contributes uniquely to our understanding of color, highlighting its complexity as a subject that bridges physics, biology, psychology, and anthropology.