Using AI in .NET Responsibly: Prompts, Guardrails, and Service Design

AI should sit inside the application like any other dependency. If the prompt is too broad, the output too loose, or the data too sensitive, the design needs work before the model call does.

What responsible AI means in practice

The idea sounds formal, but the day-to-day version is simple: decide what data can enter the prompt, what kind of answer is acceptable, and where a person still needs to check the result. If that part is vague, the whole feature becomes hard to trust.

  • Keep secrets out of prompts.
  • Use synthetic or redacted examples for testing.
  • Validate lengths, formats, and allowable content.
  • Keep AI output behind business rules and review steps.
  • Prefer a small service wrapper for model calls.
  • Log request metadata, not raw sensitive payloads.
  • Use evaluation or safety checks for risky output paths.
  • Treat the model as a helper, not a trusted source of truth.

Service design pattern

Prompt design rules

  1. Ask for a specific output shape.
  2. Keep the task narrow: summarize, classify, draft, extract.
  3. Tell the model what not to do when the risk is high.
  4. Separate system instructions from user content in your service.
public sealed record PromptRequest(string Input);
public sealed record PromptResult(string Output, bool NeedsReview);

// Example intent only: validate input, call model, validate output, then return.

Real prompt templates

Summarize the following support note in 5 bullets.
Return only action items and blockers.
Do not include any sensitive data in the output.
Classify this ticket into one of these queues:
Billing, Access, Product, or Escalation.
If the input is unclear, return NeedsReview.

Example guardrail layer

Keep the safety logic in one place so your UI and controllers stay simple.

public static class PromptSafety
{
    public static string RedactSecrets(string input)
        => input.Replace("password=", "password=[redacted]", StringComparison.OrdinalIgnoreCase);

    public static bool NeedsReview(string output)
        => output.Contains("maybe", StringComparison.OrdinalIgnoreCase)
        || output.Contains("not sure", StringComparison.OrdinalIgnoreCase);
}
public async Task<PromptResult> RunAsync(PromptRequest request)
{
    var safeInput = PromptSafety.RedactSecrets(request.Input);
    var output = await CallModelAsync(safeInput);

    return new PromptResult(
        output,
        PromptSafety.NeedsReview(output));
}

Where the safety checks belong

Good starter use cases

What I did not automate first

Why this article matters

I do not care whether the model call looks clever. I care whether the AI part stays small, visible, and safe enough that the team can live with it later.

© 2026 Anup Kumar Chandrakumaran