Skip to content

Adding HandlebarsPlanCreationException#4973

Merged
teresaqhoang merged 6 commits intomicrosoft:mainfrom
teresaqhoang:hb-planner-error-handling
Feb 23, 2024
Merged

Adding HandlebarsPlanCreationException#4973
teresaqhoang merged 6 commits intomicrosoft:mainfrom
teresaqhoang:hb-planner-error-handling

Conversation

@teresaqhoang
Copy link
Contributor

@teresaqhoang teresaqhoang commented Feb 12, 2024

Motivation and Context

Resolves #4440

This PR adds a more detailed HandlebarsPlanCreationException type, which allows users to inspect the prompt and model results, if available.

Als includes a minor update to sample to add clarifying comments.

Description

Users can catch HandlebarsPlanCreationException to inspect the prompt, proposed plan, and exception details on error. All exceptions will be bubbled up to the caller.

var planner = new HandlebarsPlanner();

try
{
     var plan = await planner.CreatePlanAsync(kernel, intent, cancellationToken);
}
catch (HandlebarsPlanCreationException ex)
{
     Console.WriteLine(ex.Message);
     Console.WriteLine(ex.InnerException?.Message);
     Console.WriteLine($"CreatePlan Prompt: {ex.CreatePlanPrompt}");
     Console.WriteLine($"Proposed plan (model output): {ex.ModelResults.Content}");
     throw ex;
}

Contribution Checklist

@teresaqhoang teresaqhoang self-assigned this Feb 12, 2024
@teresaqhoang teresaqhoang requested a review from a team as a code owner February 12, 2024 20:31
@shawncal shawncal added the .NET Issue or Pull requests regarding .NET code label Feb 12, 2024
@github-actions github-actions bot changed the title [Handlebars Planner] Option to return error details in HB Plan object instead of throwing .Net: [Handlebars Planner] Option to return error details in HB Plan object instead of throwing Feb 12, 2024
@Krzysztof318
Copy link
Contributor

But isn't this a return to how kernel errors were once handled? ADR 0004 describes a departure from such solution in favor of throwing exceptions.

@teresaqhoang teresaqhoang force-pushed the hb-planner-error-handling branch from 704cf70 to 9171a7a Compare February 15, 2024 18:25
@teresaqhoang teresaqhoang changed the title .Net: [Handlebars Planner] Option to return error details in HB Plan object instead of throwing Adding HandlebarsPlanCreationException Feb 15, 2024
@teresaqhoang
Copy link
Contributor Author

But isn't this a return to how kernel errors were once handled? ADR 0004 describes a departure from such solution in favor of throwing exceptions.

Great callout @Krzysztof318, that slipped my mind. Pivoted to creating a narrower exception type containing these details.

@teresaqhoang teresaqhoang added this pull request to the merge queue Feb 23, 2024
Merged via the queue into microsoft:main with commit 8858733 Feb 23, 2024
@teresaqhoang teresaqhoang deleted the hb-planner-error-handling branch February 23, 2024 20:56
LudoCorporateShark pushed a commit to LudoCorporateShark/semantic-kernel that referenced this pull request Aug 25, 2024
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Resolves microsoft#4440

This PR adds a more detailed `HandlebarsPlanCreationException` type,
which allows users to inspect the prompt and model results, if
available.

Als includes a minor update to sample to add clarifying comments.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

Users can catch `HandlebarsPlanCreationException` to inspect the prompt,
proposed plan, and exception details on error. All exceptions will be
bubbled up to the caller.

```
var planner = new HandlebarsPlanner();

try
{
     var plan = await planner.CreatePlanAsync(kernel, intent, cancellationToken);
}
catch (HandlebarsPlanCreationException ex)
{
     Console.WriteLine(ex.Message);
     Console.WriteLine(ex.InnerException?.Message);
     Console.WriteLine($"CreatePlan Prompt: {ex.CreatePlanPrompt}");
     Console.WriteLine($"Proposed plan (model output): {ex.ModelResults.Content}");
     throw ex;
}
```

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
Bryan-Roe pushed a commit to Bryan-Roe-ai/semantic-kernel that referenced this pull request Oct 6, 2024
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Resolves microsoft#4440

This PR adds a more detailed `HandlebarsPlanCreationException` type,
which allows users to inspect the prompt and model results, if
available.

Als includes a minor update to sample to add clarifying comments.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

Users can catch `HandlebarsPlanCreationException` to inspect the prompt,
proposed plan, and exception details on error. All exceptions will be
bubbled up to the caller.

```
var planner = new HandlebarsPlanner();

try
{
     var plan = await planner.CreatePlanAsync(kernel, intent, cancellationToken);
}
catch (HandlebarsPlanCreationException ex)
{
     Console.WriteLine(ex.Message);
     Console.WriteLine(ex.InnerException?.Message);
     Console.WriteLine($"CreatePlan Prompt: {ex.CreatePlanPrompt}");
     Console.WriteLine($"Proposed plan (model output): {ex.ModelResults.Content}");
     throw ex;
}
```

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Net: Exceptions thrown from the HandlebarsPlanner should be specific and should contain Exception-Data.

6 participants