Prompt Engineering in Practice: Building a Custom AI Writing Assistant That Actually Works

    This article explains why general-purpose LLMs produce inconsistent content in production and how to fix it with prompt engineering. It breaks down common failure modes such as factual hallucination, instruction decay, premature output, and stale knowledge, then introduces a three-layer prompt architecture covering constraints, role definition, and workflow. You will also find guidance on externalizing configuration, integrating staged generation, running quality checks, and avoiding common pitfalls when turning a general model into a stable, auditable writing assistant.

    1. Problem Definition: Why General Models Fail to Produce Reliable Content

    Many teams introduce large language models into their content production workflow and encounter a contradictory experience: the demo looks impressive, but daily production requires constant rework. The problem is usually not the model’s capability, but the way it is being called. A general conversation without constraints is essentially a probabilistic generation process, and the output drifts depending on wording, context length, and the order of questions. To turn randomness into controllability, you first need to break the problem apart.

    The common symptoms fall into four categories:

    • Factual hallucination: On specialized, niche, or time-sensitive topics, the model tends to fill gaps with statements that are statistically “plausible,” producing precise-looking data and cases with no source.
    • Instruction decay: As the context grows longer, the weight of style and format requirements set earlier drops, the writing style regresses to the average, and hollow, template-like paragraphs appear.
    • Premature output: The model produces a complete long-form draft before requirements are clarified, which amplifies directional errors across the entire piece and makes rework extremely costly.
    • Stale knowledge: The model’s knowledge has a training cutoff. If the workflow does not include a retrieval step, time-sensitive information will inevitably be distorted.

    The shared root cause of these four problems is: missing constraints, vague roles, and an invisible process. The engineering solution is not to switch to a “smarter” model, but to write requirements as rules that machines can parse reliably and to split generation into stages that can be checked.

    2. Method Framework: A Three-Layer Prompt Architecture

    A reusable writing assistant configuration should be organized as “constraint layer - role layer - workflow layer.” Separating the responsibilities of the three layers makes it easier to iterate on each one independently and to quickly identify which layer is at fault when the output quality drops.

    2.1 Constraint Layer: Define the Non-Negotiable Red Lines

    The constraint layer addresses “what must not be done,” and its priority should be explicitly declared as the highest so that it is not overridden when it conflicts with later style requirements. At a minimum, it should include the following items:

    1. Mandatory sourcing: All data, citations, and cases must come from search results actually executed in the workflow. When retrieval returns nothing, output “no reliable source available” and do not fill the gap with speculation.
    2. Confirmation first: Do not produce body text before the topic, target audience, core argument, and outline are confirmed.
    3. Chunked delivery: Generate module by module, pausing after each section to wait for feedback, so that local revisions do not affect the whole piece.
    4. Uncertainty labeling: Use explicit markers for statements that cannot be verified, rather than glossing over them with vague wording.

    Illustrative constraint snippet:

    1. <constraints priority="highest">
    2. <rule id="no-fabrication">
    3. Do not fabricate data, cases, citations, or links; only use content from <research_results>.
    4. If evidence is insufficient, output "Insufficient evidence, additional retrieval required".
    5. </rule>
    6. <rule id="confirm-before-write">
    7. Do not output body text before the outline and audience are confirmed.
    8. </rule>
    9. <rule id="chunked-delivery">
    10. Output only one section at a time and wait for the "continue" instruction.
    11. </rule>
    12. </constraints>

    2.2 Role Layer: Express Identity as Executable Capability

    A statement like “you are an editor” produces almost no constraint because it gives no criteria for judgment. The role layer should translate identity into observable behavioral traits: domain experience, reader profile, explanation strategy, and style boundaries.

    • Domain and experience: Specify the vertical domain and years of experience so that terminology density and the way examples are used have a stable baseline.
    • Reader profile: State the reader’s knowledge starting point to determine which concepts need groundwork and which can be assumed as known.
    • Explanation strategy: Require “conclusion first, then mechanism, then analogy” to avoid a long preamble.
    • Style boundaries: Explicitly prohibit marketing-style expressions and exaggerated adjectives, and specify ranges for sentence and paragraph length.

    Illustrative role snippet:

    1. <role>
    2. You are a technology editor-in-chief with ten years of experience, and your readers are developers with basic programming skills.
    3. Explanation order: conclusion -> mechanism -> analogy.
    4. Style: restrained, specific, verifiable; no marketing language or exaggerated modifiers.
    5. Paragraph length: 3-5 sentences per paragraph; at least one concrete detail or example every 300 words.
    6. </role>

    2.3 Workflow Layer: Split Generation into a Checkable Pipeline

    The value of the workflow layer is to turn “one-shot generation” into “multiple small confirmations,” where each step has a clear deliverable and acceptance criteria. Five stages are recommended:

    1. Requirement clarification: Restate your understanding, list information gaps, and ask at most three key questions.
    2. Retrieval and evidence gathering: Search around the argument, aiming to produce no fewer than three verifiable pieces of evidence, and label the source type (official documentation, papers, industry reports, etc.).
    3. Structure building: Output title candidates, the core argument, a section outline, and an evidence mapping table for each section.
    4. Section writing: Generate section by section, and provide layout suggestions at the same time (where to bold, where to use lists, where an image or code block is appropriate).
    5. Self-check and review: Check facts, structure, style, and timeliness against a checklist, and output an issue list with revision suggestions.

    Illustrative workflow snippet:

    1. <workflow>
    2. <step name="clarify" output="gap_list"/>
    3. <step name="research" output="evidence_table" min_items="3"/>
    4. <step name="outline" output="outline_with_evidence_map"/>
    5. <step name="draft" output="single_section" requires="continue"/>
    6. <step name="review" output="issue_list"/>
    7. </workflow>

    3. Configuration and Integration: From Template to Reusable Asset

    The configuration process can be broken into three steps. First, write the three layers above as structured text, have the model convert it into a standard markup format, and explicitly declare that the constraint layer has the highest priority. Second, save the configuration as a reusable custom instruction or assistant configuration to avoid information loss from pasting it repeatedly in every session. Third, establish version management: record the change points and the resulting quality differences for each revision to prevent the configuration from becoming “messier with every change.”

    For engineering implementation, the configuration can be externalized as a file and injected by the application layer before each request, rather than hard-coded in business logic:

    1. # Illustrative: externalized config + staged invocation
    2. CONFIG = load_prompt_config("writer_config.xml") # contains constraints/role/workflow
    3. def run_stage(stage: str, context: dict) -> str:
    4. prompt = render(CONFIG, stage=stage, context=context)
    5. return call_model(prompt) # implementation to be replaced by the business team
    6. # Advance stage by stage; persist each stage's output for auditing and reproduction
    7. outline = run_stage("outline", {"topic": topic, "audience": audience})

    There are three engineering key points. First, retrieval and generation must be separated, with retrieval results injected as independent context for traceability. Second, each stage’s output should be persisted to form an auditable chain. Third, lower sampling parameters such as temperature for factual tasks and raise them moderately for creative tasks, setting them separately per scenario.

    4. Quality Checks and Common Pitfalls

    Before going live, it is advisable to fix a checklist that turns subjective judgment into checkable items:

    • Does every data point have a corresponding source, and is the source primary material?
    • Do the outline and the body text correspond one-to-one, and are there paragraphs without supporting evidence?
    • Are there marketing-style or absolute statements?
    • Has time-sensitive content been confirmed by the current retrieval?
    • Are the layout suggestions executable, and do the code and examples run?

    Common pitfalls are also worth watching for. First, writing too many and too detailed constraints, which causes the model to lose track of some of them; keep them within ten items and sort them by importance. Second, skipping the confirmation step and asking directly for a long draft, which looks efficient but actually causes the most rework. Third, treating the configuration as a one-time task without iterating on business and reader feedback. Fourth, over-relying on the model’s self-check, when key facts still need manual or programmatic verification as a fallback.

    5. Conclusion

    Turning a general model into a stable writing assistant is not about finding some “hidden feature,” but about establishing a prompt engineering standard with clear constraints, specific roles, and a visible workflow, combined with retrieval-based evidence gathering and staged verification to form a closed loop. When the output process is reproducible, auditable, and locally revisable, content production truly shifts from inspiration-driven to engineering-driven. If you are already using the relevant model services from Baidu AI Cloud, it is recommended to consolidate the above configuration and verification steps into team assets, combine them with general capabilities such as logging and monitoring alerts, and continuously observe output quality and iterate.