Skip to content
TheChatArchiveThe Chat Archive
Geminigemini-2.5-pro-preview-03-25· GoogleHugging Face LMArena Human Preference 140K

If I want to feed a hierarchical conversation - like from Hacker News - to an LLM what…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-3-5-sonnet-20241022’s answer.
  1. User

    If I want to feed a hierarchical conversation - like from Hacker News - to an LLM what are the best ways to format those comments in a prompt? Show a simple example and then the output of different notations

  2. Gemini Assistant

    Okay, let's break down how to format hierarchical Hacker News-style conversations for an LLM. The key challenge is preserving the reply structure (who replied to whom) so the LLM understands the conversational flow and context.

    Core Problem: Flatting the conversation loses the crucial parent-child relationships between comments. We need a notation that encodes this structure within the text prompt.

    Simple Example Conversation:

    Let's use a tiny, fictional HN thread:

    • Post Title: Show HN: My new project, "CatChat", translates meows to English.
    • User: alice (ID: 1)
      • Wow, this is hilarious and potentially revolutionary! Does it handle different breeds?
    • User: bob (ID: 2, replying to 1)
      • Seconded! My Siamese sounds nothing like my Maine Coon. Curious about the underlying model.
    • User: charlie (ID: 3, replying to 2)
      • Probably a transformer tuned on a massive dataset of cat vocalizations? The real trick is labelling that data!
    • User: dave (ID: 4, replying to 1)
      • Is the code open source? Would love to contribute.
    • User: eve (ID: 5, top-level comment)
      • Cool idea, but worried about privacy implications for the cats! 😉

    Different Formatting Notations:

    Here are a few ways to format this, with explanations:

    Method 1: Indentation (Simple & Human-Readable)

    This method uses spaces or tabs to visually represent the hierarchy. It's often the most intuitive.

    Post Title: Show HN: My new project, "CatChat", translates meows to English.
    
    [Comment 1 by alice]
    Wow, this is hilarious and potentially revolutionary! Does it handle different breeds?
    
      [Comment 2 by bob, replying to alice]
      Seconded! My Siamese sounds nothing like my Maine Coon. Curious about the underlying model.
    
        [Comment 3 by charlie, replying to bob]
        Probably a transformer tuned on a massive dataset of cat vocalizations? The real trick is labelling that data!
    
      [Comment 4 by dave, replying to alice]
      Is the code open source? Would love to contribute.
    
    [Comment 5 by eve]
    Cool idea, but worried about privacy implications for the cats! 😉
    
    • Pros: Very easy to read and understand the structure visually. Many LLMs handle indentation reasonably well as it's common in code and outlines.
    • Cons: Can be sensitive to the exact number of spaces/tabs. Might require explicit instructions for the LLM to pay attention to indentation. Can become visually complex with deep nesting. Whitespace might sometimes be ignored or normalized by LLMs or input processing.

    Method 2: Explicit Parent Linking (Precise & Robust)

    This method assigns unique IDs to each comment and explicitly states the parent ID for replies.

    Post Title: Show HN: My new project, "CatChat", translates meows to English.
    
    [Comment ID: 1, Author: alice, Parent: Post]
    Wow, this is hilarious and potentially revolutionary! Does it handle different breeds?
    
    [Comment ID: 2, Author: bob, Parent: 1]
    Seconded! My Siamese sounds nothing like my Maine Coon. Curious about the underlying model.
    
    [Comment ID: 3, Author: charlie, Parent: 2]
    Probably a transformer tuned on a massive dataset of cat vocalizations? The real trick is labelling that data!
    
    [Comment ID: 4, Author: dave, Parent: 1]
    Is the code open source? Would love to contribute.
    
    [Comment ID: 5, Author: eve, Parent: Post]
    Cool idea, but worried about privacy implications for the cats! 😉
    
    • Pros: Unambiguous structure. The relationship is explicitly stated, making it very clear for the LLM. Less sensitive to whitespace issues. Scales well programmatically.
    • Cons: Less immediately readable for humans than indentation. More verbose. Requires generating and tracking unique IDs.

    Method 3: Path Notation (Compact Hierarchy)

    Uses a path-like string to indicate the position in the tree. Similar to file paths or breadcrumbs.

    Post Title: Show HN: My new project, "CatChat", translates meows to English.
    
    [Comment Path: /1, Author: alice]
    Wow, this is hilarious and potentially revolutionary! Does it handle different breeds?
    
    [Comment Path: /1/2, Author: bob]
    Seconded! My Siamese sounds nothing like my Maine Coon. Curious about the underlying model.
    
    [Comment Path: /1/2/3, Author: charlie]
    Probably a transformer tuned on a massive dataset of cat vocalizations? The real trick is labelling that data!
    
    [Comment Path: /1/4, Author: dave]
    Is the code open source? Would love to contribute.
    
    [Comment Path: /5, Author: eve]
    Cool idea, but worried about privacy implications for the cats! 😉
    
    • Pros: Clearly encodes hierarchy and depth in a relatively compact way. Programmatically derivable.
    • Cons: Can look a bit technical. Might require the LLM to specifically parse the path structure. Readability decreases slightly compared to indentation for quick glances.

    Method 4: Markdown Blockquotes (Leveraging Existing Conventions)

    Uses markdown quoting (>) to indicate replies, increasing the level for deeper nesting. Often needs explicit user tags.

    Post Title: Show HN: My new project, "CatChat", translates meows to English.
    
    **alice:** Wow, this is hilarious and potentially revolutionary! Does it handle different breeds?
    
    > **bob (replying to alice):** Seconded! My Siamese sounds nothing like my Maine Coon. Curious about the underlying model.
    >
    > > **charlie (replying to bob):** Probably a transformer tuned on a massive dataset of cat vocalizations? The real trick is labelling that data!
    
    > **dave (replying to alice):** Is the code open source? Would love to contribute.
    
    **eve:** Cool idea, but worried about privacy implications for the cats! 😉
    
    • Pros: Uses a familiar convention (email/forum quoting). Visually indicates replies.
    • Cons: Can get ambiguous if not careful. Doesn't explicitly link a reply to a specific parent comment if multiple comments exist at the same level (e.g., both Bob and Dave reply to Alice). Adding (replying to X) helps mitigate this. Top-level comments need distinct formatting (no >).

    Key Considerations & Recommendations:

    1. LLM Sensitivity: Some LLMs are better than others at interpreting implicit structure like indentation. More explicit methods (Parent IDs, Paths) are generally safer but might require more prompt engineering effort if the LLM isn't specifically trained on them.
    2. Task: What do you want the LLM to do?
      • Summarization: Indentation or Path notation might be sufficient as the LLM needs the flow.
      • Analysis (e.g., "Find replies to Bob"): Explicit Parent IDs are best.
      • Generating a Reply: Any method could work, but the LLM needs to understand where the new reply fits. Explicit IDs or Paths make this easiest to specify.
    3. Clarity of Instruction: Regardless of the format, tell the LLM how to interpret it. For example:
      • "The following is a conversation thread from Hacker News. Comments are indented to show replies."
      • "Here is a conversation thread. Each comment has an ID and a Parent ID indicating which comment it replies to ('Parent: Post' means it's a top-level comment)."
    4. Context Window: Very long threads might exceed the context window. More verbose formats (like Explicit Parent Linking with lots of metadata) consume more tokens. Indentation is often the most token-efficient.
    5. Testing: The "best" way often depends on the specific LLM you're using. Try different formats with your target model and see which one yields the best results for your specific task.

    Recommendation:

    • Start with Indentation (Method 1): It's often good enough, intuitive, and relatively token-efficient. Add clear author/metadata tags like [Comment by userX].
    • If Indentation Fails or Precision is Crucial: Move to Explicit Parent Linking (Method 2) or Path Notation (Method 3). These are more robust against LLM interpretation quirks.
    • Use Metadata: Including author names (alice, bob) is crucial for the LLM to track who said what. Including comment IDs can also be helpful even with indentation.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.