Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs]: Chain of thought prompting usability isn't documented #1412

Closed
prrao87 opened this issue Feb 4, 2025 · 2 comments
Closed

[Docs]: Chain of thought prompting usability isn't documented #1412

prrao87 opened this issue Feb 4, 2025 · 2 comments
Assignees

Comments

@prrao87
Copy link
Contributor

prrao87 commented Feb 4, 2025

The existing chain of thought prompting method in the docs isn't very concise or readable from a prompt perspective - the user has to type out this long and drawn out string as part of the BAML function.

Instead, it would be simpler to extract out the CoT prompt into a template_string and call that from inside the main function.

Something like this based on my chat on Discord (maybe there's a better way to write it than the example shown?)

template_string CoT() #"
    Before you output the JSON, please explain your
    reasoning step-by-step. Here is an example on how to do this:
    'If we think step by step we can see that ...
     therefore the output JSON is:
    {
      ... the json schema ...
    }'
"#

function MyFunction() {
    ...
    ...
   {{ CoT("..") }}
}

Having some form of abstracted way to do this that separates out the CoT concerns from the rest of the prompt would be nice, and should be documented to help users do CoT prompting more elegantly.

@ansu86d
Copy link

ansu86d commented Feb 11, 2025

I am able to get some basic CoT by adding it as an attribute to the output class

Adding CoT property to Output object

class Receipt { establishment_name string date string @description("ISO8601 formatted date") total int @description("The total amount of the receipt") currency string items Item[] @description("The items on the receipt") chain_of_thought string[] @description("Explain your reasoning step by step") }

Response:

{ "establishment_name": "Brasa Rotisserie", "date": "2024-01-27T20:50:00", "total": 23, "currency": "USD", "items": [ { "name": "Roasted Pork & Over Easy Egg Bowl", "price": 15.25, "quantity": 1 }, { "name": "Indeed Mex Honey Lite", "price": 6.5, "quantity": 1 } ], "chain_of_thought": [ "The receipt is from Brasa Rotisserie.", "The date and time on the receipt is 1/27/24 at 8:50 PM, which translates to the ISO8601 format as 2024-01-27T20:50:00.", "The total amount is listed as $23.88. USD is inferred as the currency because the establishment is located in Minnesota, USA.", "Two items are listed: 'Roasted Pork & Over Easy Egg Bowl' priced at $15.25 and 'Indeed Mex Honey Lite' priced at $6.50. No additional quantity information is provided, so quantity is assumed to be 1 by default.", "Subtotal is correctly calculated as $21.75, which matches the sum of the item prices (15.25 + 6.50).", "The tax is $2.13, making the total $23.88." ] }

Prompt Fiddle : https://www.promptfiddle.com/BAML-Examples-RsZnY

This might not be an elegant solution by glueing it to the output object , but the fact that just adding a new property with the description with no changes to the 'prompt' section highlights the ability to extract reasoning in a structured manner

@prrao87 @hellovai @aaronvg

@hellovai hellovai self-assigned this Feb 11, 2025
github-merge-queue bot pushed a commit that referenced this issue Feb 12, 2025
<!-- ELLIPSIS_HIDDEN -->



> [!IMPORTANT]
> Improves documentation for chain-of-thought prompting with examples
and reusable snippets for various techniques.
> 
>   - **Documentation Enhancements**:
> - Expanded `chain-of-thought.mdx` to include detailed explanations and
examples of four techniques for chain-of-thought prompting.
> - Added visual aid with an image and reference to Wei et al. (2022).
> - Included `Tip` and `Info` sections to guide users on technique
selection and BAML's capabilities.
>   - **Code Examples**:
> - Provided `baml` code snippets for each technique, demonstrating how
to implement chain-of-thought prompting in functions like
`GetOrderInfo`.
> - Introduced `template_string` for reusable chain-of-thought snippets.
>   - **Techniques Covered**:
>     - Technique 1: Reasoning before outputting structured object.
> - Technique 2: Flexible reasoning before outputting structured object.
>     - Technique 3: Embedding reasoning in the structured object.
> - Technique 4: Embedding reasoning as comments in the structured
object.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup>
for 0a5932e. It will automatically
update as commits are pushed.</sup>

<!-- ELLIPSIS_HIDDEN -->
@prrao87
Copy link
Contributor Author

prrao87 commented Feb 12, 2025

This is great, thanks a ton!

@prrao87 prrao87 closed this as completed Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants