Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

Users need to specify expected response formats in LLM prompts without including example data, which wastes tokens. The request was for templates like {"name":"name of the person","age":"age of the person"} in TOON format.

Changes

New API functions:

  • generate_structure(schema, options) - Generates TOON structure templates from dict schemas
  • generate_structure_from_pydantic(model_class, options, include_descriptions) - Generates templates from Pydantic models

Implementation:

  • toon/structure_generator.py - Core template generation logic with support for nested objects, arrays, and custom delimiters
  • Exports added to toon/__init__.py

Tests & Documentation:

  • 16 new tests covering edge cases, nested structures, arrays, and Pydantic integration
  • Example file with real-world use cases (examples/structure_template_usage.py)
  • API reference and usage guide in README

Usage

from toon import generate_structure

# Dict-based schema
schema = {
    "name": "name of the person",
    "age": "age of the person",
    "occupation": "job description"
}

structure = generate_structure(schema)
# Output:
# name: <name of the person>
# age: <age of the person>
# occupation: <job description>

# Use in LLM prompt
prompt = f"Extract data in this format:\n{structure}"
# Pydantic model support
from pydantic import BaseModel, Field

class Person(BaseModel):
    name: str = Field(description="full name")
    age: int = Field(description="age in years")

structure = generate_structure_from_pydantic(Person)
# Automatically uses field descriptions

Arrays generate tabular templates:

schema = {"users": [{"id": "user id", "name": "user name"}]}
# Output:
# users[N]{id,name}:
#   <user id>,<user name>
#   ...

Closes issue regarding response structure templates without examples.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • openaipublic.blob.core.windows.net
    • Triggering command: python -m pytest tests/ -v (dns block)
    • Triggering command: python -m pytest tests/ -v --tb=short (dns block)
    • Triggering command: python -m pytest tests/ -q --tb=no (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>response structure for prompt response</issue_title>
<issue_description>Is your feature request related to a problem? Please describe.
response structure for prompt like response struct:{"name":"name of the person","age":"age of the person","occupation":"job description of the person"} like this without mentioning examples so that we can add it to the prompt
Describe the solution you'd like
universal response structure for the prompt in toon instead of json without mentioning examples

Describe alternatives you've considered
no.

Additional context
@FrancescoSaverioZuppichini
@lurenss

</issue_description>

Comments on the Issue (you are @copilot in this section)

@VinciGit00 Hi @Pavansomisetty21 thank you for the feedback,

we will take care about that.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: VinciGit00 <88108002+VinciGit00@users.noreply.github.com>
Copilot AI changed the title [WIP] Add universal response structure for prompt feat: add structure template generation for LLM prompts Nov 20, 2025
Copilot AI requested a review from VinciGit00 November 20, 2025 19:00
Copilot finished work on behalf of VinciGit00 November 20, 2025 19:00
@VinciGit00 VinciGit00 marked this pull request as ready for review November 20, 2025 19:05
@VinciGit00 VinciGit00 merged commit 7ac7e14 into main Nov 20, 2025
1 check passed
@VinciGit00 VinciGit00 deleted the copilot/update-prompt-response-structure branch November 20, 2025 19:22
@github-actions
Copy link

🎉 This PR is included in version 1.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

response structure for prompt response

2 participants