[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"article-prompt-engineering-agents-structured-outputs-en":3,"tags-prompt-engineering-agents-structured-outputs-en":30,"related-lang-prompt-engineering-agents-structured-outputs-en":41,"related-posts-prompt-engineering-agents-structured-outputs-en":45,"series-ai-agent-28a1b97c-06c1-4112-8fb5-a9ff8e58fcd9":82},{"id":4,"title":5,"content":6,"summary":7,"source":8,"source_url":9,"author":10,"image_url":11,"keywords":12,"language":18,"translated_content":10,"views":19,"is_premium":20,"created_at":21,"updated_at":21,"cover_image":11,"published_at":22,"rewrite_status":23,"rewrite_error":10,"rewritten_from_id":24,"slug":25,"category":26,"related_article_id":27,"status":28,"google_indexed_at":29,"x_posted_at":10,"tweet_text":10,"title_rewritten_at":10,"title_original":10,"key_takeaways":10,"topic_cluster_id":10,"embedding":10,"is_canonical_seed":20},"28a1b97c-06c1-4112-8fb5-a9ff8e58fcd9","Prompt Engineering for Agents and Structured Outputs","\u003Cp>Large language models can now hold \u003Cstrong>128k, 200k, even 1M tokens\u003C\u002Fstrong> of context, but that does not mean they stay obedient or accurate. Once you move from chat demos into agent workflows, prompt design becomes a control system for reasoning, memory, and output shape.\u003C\u002Fp>\u003Cp>The article from \u003Ca href=\"https:\u002F\u002Fcodefinity.com\u002Fblog\u002FAdvanced-Prompt-Engineering-for-Agents,-Reasoning-and-Structured-Outputs\" target=\"_blank\" rel=\"noopener\">Codefinity\u003C\u002Fa> gets this right: the hard part is not writing longer prompts, it is designing prompts that survive tool calls, long histories, and machine-to-machine handoffs. That shift matters whether you are using \u003Ca href=\"https:\u002F\u002Fopenai.com\" target=\"_blank\" rel=\"noopener\">OpenAI\u003C\u002Fa>, \u003Ca href=\"https:\u002F\u002Fwww.anthropic.com\" target=\"_blank\" rel=\"noopener\">Anthropic\u003C\u002Fa>, or local stacks like \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fvllm-project\u002Fvllm\" target=\"_blank\" rel=\"noopener\">vLLM\u003C\u002Fa>.\u003C\u002Fp>\u003Ch2>Prompt engineering is a systems problem\u003C\u002Fh2>\u003Cp>In production, a prompt is closer to an interface contract than a clever instruction. It defines the model’s role, the boundaries of its memory, the shape of its output, and the rules it must follow when context gets messy. That is why prompts that look fine in a notebook often break when they hit a real app.\u003C\u002Fp>\n\u003Cfigure class=\"my-6\">\u003Cimg src=\"https:\u002F\u002Fxxdpdyhzhpamafnrdkyq.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fcovers\u002Finline-1775164941484-fp41.png\" alt=\"Prompt Engineering for Agents and Structured Outputs\" class=\"rounded-xl w-full\" loading=\"lazy\" \u002F>\u003C\u002Ffigure>\n\u003Cp>The failure modes are familiar to anyone building with LLMs. Instructions get buried in long chats, reasoning becomes inconsistent, JSON comes back malformed, and agents loop on failed tool calls until your logs look like a cry for help. The fix is not “more detail” in the abstract. The fix is a prompt architecture that anticipates these failure modes.\u003C\u002Fp>\u003Cp>For developers, the practical takeaway is simple: write prompts the way you would design an API. Define inputs, expected behavior, error handling, and output format before you ask the model to do any work.\u003C\u002Fp>\u003Cul>\u003Cli>Long prompts degrade instruction following as the conversation grows\u003C\u002Fli>\u003Cli>Reasoning quality improves when the model is given a clear structure\u003C\u002Fli>\u003Cli>Structured outputs need a schema, not a vague request for JSON\u003C\u002Fli>\u003Cli>Agent prompts need termination rules or they can loop forever\u003C\u002Fli>\u003C\u002Ful>\u003Ch2>Reasoning works better with structure\u003C\u002Fh2>\u003Cp>The article revisits chain-of-thought prompting, which became widely known after the 2022 paper \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2201.11903\" target=\"_blank\" rel=\"noopener\">Chain-of-Thought Prompting Elicits Reasoning in Large Language Models\u003C\u002Fa>. The core idea still holds up: models do better on multi-step tasks when they are asked to reason before answering.\u003C\u002Fp>\u003Cp>But there is a catch. A plain “think step by step” prompt helps with simple arithmetic and logic, yet it is too loose for production work. If you want reliable reasoning, you need to shape the process. That is why the article recommends zero-shot CoT, few-shot CoT, scratchpad separation, and self-consistency sampling as different tools for different levels of risk.\u003C\u002Fp>\u003Cblockquote>“Let’s think step by step.” — \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2201.11903\" target=\"_blank\" rel=\"noopener\">Chain-of-Thought Prompting Elicits Reasoning in Large Language Models\u003C\u002Fa>\u003C\u002Fblockquote>\u003Cp>That quote became famous because it captures the simplest possible reasoning trigger. In practice, though, the stronger pattern is to separate internal reasoning from user-facing output. If the model writes its thought process into the final answer, it can contradict itself or expose intermediate guesses that should have stayed hidden.\u003C\u002Fp>\u003Cp>Self-consistency is the most interesting idea in this section. Instead of trusting one reasoning path, you sample several, then pick the answer that appears most often. It is more expensive, but on high-stakes tasks that extra cost is easier to justify than a silent mistake.\u003C\u002Fp>\u003Cul>\u003Cli>Zero-shot CoT uses a trigger like “Let’s think step by step”\u003C\u002Fli>\u003Cli>Few-shot CoT gives worked examples and usually performs better on multi-step tasks\u003C\u002Fli>\u003Cli>Scratchpad separation keeps reasoning away from the final response\u003C\u002Fli>\u003Cli>Self-consistency often uses 3 to 5 samples to stabilize answers\u003C\u002Fli>\u003C\u002Ful>\u003Ch2>Long context needs anchoring, not optimism\u003C\u002Fh2>\u003Cp>Modern models can accept huge context windows, but the article correctly warns against confusing capacity with reliability. Research on the “lost in the middle” effect shows that models often remember information near the start or end of a long prompt better than information buried in the middle. In other words, a 100k-token prompt is still fragile.\u003C\u002Fp>\n\u003Cfigure class=\"my-6\">\u003Cimg src=\"https:\u002F\u002Fxxdpdyhzhpamafnrdkyq.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fcovers\u002Finline-1775164928524-p8k0.png\" alt=\"Prompt Engineering for Agents and Structured Outputs\" class=\"rounded-xl w-full\" loading=\"lazy\" \u002F>\u003C\u002Ffigure>\n\u003Cp>This is where prompt layout matters more than most teams expect. Critical instructions should be repeated near the end of the prompt, not just placed once at the top. Section markers help too, because they give the model a clear map of what is data, what is history, and what is the current task.\u003C\u002Fp>\u003Cp>Progressive summarization is another practical trick. Instead of feeding the entire conversation back into the model forever, keep a running summary of completed work and preserve only the most recent turns in full. That keeps the prompt smaller while still preserving the state the agent actually needs.\u003C\u002Fp>\u003Cp>The article also calls out prompt injection, which is still one of the most annoying problems in agent systems. If a retrieved document or tool response contains instructions, the model may treat those instructions as if they came from you unless you explicitly mark them as untrusted data.\u003C\u002Fp>\u003Cul>\u003Cli>Place key instructions at both the start and near the end of long prompts\u003C\u002Fli>\u003Cli>Use XML-style tags or clear delimiters for documents and tool output\u003C\u002Fli>\u003Cli>Keep a rolling summary instead of replaying the entire history\u003C\u002Fli>\u003Cli>Mark external content as data, never as instructions\u003C\u002Fli>\u003C\u002Ful>\u003Ch2>Structured outputs are contracts, not wishes\u003C\u002Fh2>\u003Cp>The most useful part of the article may be its treatment of structured output. Asking a model to “return JSON” is fragile. If the downstream system expects a valid object, you need an output contract with explicit fields, types, and null handling rules.\u003C\u002Fp>\u003Cp>That is why schema-first prompting matters. If the model knows the exact shape before it starts generating, it is less likely to invent fields or drift into prose. Tools such as \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\" target=\"_blank\" rel=\"noopener\">Outlines\u003C\u002Fa> and \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Finstructor-ai\u002Finstructor\" target=\"_blank\" rel=\"noopener\">Instructor\u003C\u002Fa> push this further by constraining generation at the token level or through API wrappers. On the API side, native structured outputs from providers like \u003Ca href=\"https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Fstructured-outputs\" target=\"_blank\" rel=\"noopener\">OpenAI Structured Outputs\u003C\u002Fa> reduce the chance of parse failures.\u003C\u002Fp>\u003Cp>For teams building extraction pipelines, the numbers matter. A single malformed JSON response can break an ingestion job, delay a workflow, or force brittle retry logic. Constrained generation avoids that by making invalid output impossible rather than merely unlikely.\u003C\u002Fp>\u003Cp>There is also a subtle but important point about optional fields. Models love to fill blanks with guesses. If a value is unknown, the prompt should say to use \u003Ccode>null\u003C\u002Fcode> rather than inventing an answer. That one line can save a lot of cleanup later.\u003C\u002Fp>\u003Cul>\u003Cli>Schema-first prompts define field names, types, and allowed values before the task\u003C\u002Fli>\u003Cli>Constrained generation prevents invalid JSON at the sampling level\u003C\u002Fli>\u003Cli>Null handling is safer than guessing for missing data\u003C\u002Fli>\u003Cli>Complex nested objects often work better when generated in stages\u003C\u002Fli>\u003C\u002Ful>\u003Ch2>Agent prompts need boundaries and stop rules\u003C\u002Fh2>\u003Cp>Agent prompts are different from single-turn prompts because they have to survive repeated tool calls, partial failures, and changing goals. The article breaks this down well: the system prompt should define the agent’s role, the tools it can use, how it should plan, and when it must stop.\u003C\u002Fp>\u003Cp>That is especially important in workflows built around \u003Ca href=\"https:\u002F\u002Fwww.langchain.com\" target=\"_blank\" rel=\"noopener\">LangChain\u003C\u002Fa>, \u003Ca href=\"https:\u002F\u002Fwww.llamaindex.ai\" target=\"_blank\" rel=\"noopener\">LlamaIndex\u003C\u002Fa>, or custom tool loops. Without explicit termination logic, an agent can keep trying the same broken action, retrying until your rate limits or patience run out.\u003C\u002Fp>\u003Cp>The article’s advice here is refreshingly concrete: define what “done” means, limit retries, and ask the agent to request only the data it needs for the current step. That is the difference between a useful assistant and a system that quietly burns tokens while pretending to think.\u003C\u002Fp>\u003Cp>Here is the comparison that matters most in practice:\u003C\u002Fp>\u003Cul>\u003Cli>\u003Cstrong>Single-turn prompts\u003C\u002Fstrong> optimize for one answer and one output\u003C\u002Fli>\u003Cli>\u003Cstrong>Reasoning prompts\u003C\u002Fstrong> optimize for multi-step thinking and verification\u003C\u002Fli>\u003Cli>\u003Cstrong>Agent prompts\u003C\u002Fstrong> optimize for repeated actions, tool use, and stop conditions\u003C\u002Fli>\u003Cli>\u003Cstrong>Structured-output prompts\u003C\u002Fstrong> optimize for machine parsing and downstream automation\u003C\u002Fli>\u003C\u002Ful>\u003Cp>Once you see those as different prompt classes, the design choices make more sense. A prompt for classification should not look like a prompt for a database agent, and a prompt for a database agent should not look like a chat assistant that explains itself to a human.\u003C\u002Fp>\u003Ch2>What developers should do next\u003C\u002Fh2>\u003Cp>The main lesson is that \u003Ca href=\"\u002Fnews\u002Fprompt-engineering-explained-without-the-hype-en\">prompt engineering\u003C\u002Fa> has matured into engineering, full stop. If you are building with agents or structured outputs, stop treating prompts like copywriting and start treating them like contracts with failure modes.\u003C\u002Fp>\u003Cp>If I had to choose one action item from this article, it would be this: audit your highest-value prompt and ask whether it has explicit reasoning structure, a context strategy, an output schema, and a stop rule. If any of those are missing, that prompt is probably doing too much by accident.\u003C\u002Fp>\u003Cp>The next wave of improvement will probably come from teams that stop asking models to “be smart” and start telling them exactly how to behave under pressure. That is where the real gains are hiding.\u003C\u002Fp>","Prompt engineering gets harder in production: reasoning, long contexts, JSON contracts, and agent loops all need different prompt tactics.","codefinity.com","https:\u002F\u002Fcodefinity.com\u002Fblog\u002FAdvanced-Prompt-Engineering-for-Agents,-Reasoning-and-Structured-Outputs",null,"https:\u002F\u002Fxxdpdyhzhpamafnrdkyq.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fcovers\u002Finline-1775164941484-fp41.png",[13,14,15,16,17],"prompt engineering","AI agents","structured outputs","chain of thought","JSON schema","en",2,false,"2026-04-02T21:21:45.840568+00:00","2026-04-02T21:21:45.817+00:00","done","946f29fe-1c4e-4a64-a76b-add1694278f3","prompt-engineering-agents-structured-outputs-en","ai-agent","f8c44ca5-e1b5-4b51-a7e5-61cdf8fa5ab9","published","2026-04-07T09:01:02.383+00:00",[31,33,35,37,39],{"name":13,"slug":32},"prompt-engineering",{"name":17,"slug":34},"json-schema",{"name":36,"slug":36},"chain-of-thought",{"name":14,"slug":38},"ai-agents",{"name":15,"slug":40},"structured-outputs",{"id":27,"slug":42,"title":43,"language":44},"prompt-engineering-agents-structured-outputs-zh","Agent 與結構化輸出提示詞實戰","zh",[46,52,58,64,70,76],{"id":47,"slug":48,"title":49,"cover_image":50,"image_url":50,"created_at":51,"category":26},"c5d4bc11-1f4d-438c-b644-a8498826e1ab","claude-agent-dreaming-outcomes-multiagent-en","Claude给Agent加了“做梦”功能","https:\u002F\u002Fxxdpdyhzhpamafnrdkyq.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fcovers\u002Finline-1778868649463-f5qv.png","2026-05-15T18:10:25.29539+00:00",{"id":53,"slug":54,"title":55,"cover_image":56,"image_url":56,"created_at":57,"category":26},"fda44d24-7baf-4d91-a7f9-bbfecae20a27","switch-ai-outputs-markdown-to-html-en","How to Switch AI Outputs from Markdown to HTML","https:\u002F\u002Fxxdpdyhzhpamafnrdkyq.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fcovers\u002Finline-1778743249827-wmsr.png","2026-05-14T07:20:22.631724+00:00",{"id":59,"slug":60,"title":61,"cover_image":62,"image_url":62,"created_at":63,"category":26},"064275f5-4282-47c3-8e4a-60fe8ac99246","anthropic-cat-wu-proactive-ai-assistants-en","Anthropic’s Cat Wu on proactive AI assistants","https:\u002F\u002Fxxdpdyhzhpamafnrdkyq.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fcovers\u002Finline-1778735465548-a92i.png","2026-05-14T05:10:31.723441+00:00",{"id":65,"slug":66,"title":67,"cover_image":68,"image_url":68,"created_at":69,"category":26},"423ac8ad-2886-42a9-8dd8-78e5d43a1574","how-to-run-hermes-agent-on-discord-en","How to Run Hermes Agent on Discord","https:\u002F\u002Fxxdpdyhzhpamafnrdkyq.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fcovers\u002Finline-1778724656141-i30t.png","2026-05-14T02:10:35.727086+00:00",{"id":71,"slug":72,"title":73,"cover_image":74,"image_url":74,"created_at":75,"category":26},"776a562c-99a6-4a6b-93a0-9af40300f3f2","why-ragflow-is-the-right-open-source-rag-engine-to-self-host-en","Why RAGFlow is the right open-source RAG engine to self-host","https:\u002F\u002Fxxdpdyhzhpamafnrdkyq.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fcovers\u002Finline-1778674254587-0pxn.png","2026-05-13T12:10:25.721583+00:00",{"id":77,"slug":78,"title":79,"cover_image":80,"image_url":80,"created_at":81,"category":26},"322ec8bc-61d3-4c80-bb9e-a19941e137c6","how-to-add-temporal-rag-in-production-en","How to Add Temporal RAG in Production","https:\u002F\u002Fxxdpdyhzhpamafnrdkyq.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fcovers\u002Finline-1778667085221-0mox.png","2026-05-13T10:10:31.619892+00:00",[83,88,93,98,103,108,113,118,123,128],{"id":84,"slug":85,"title":86,"created_at":87},"03db8de8-8dc2-4ac1-9cf7-898782efbb1f","anthropic-claude-ai-agent-task-automation-en","Anthropic's Claude AI Agent: A New Era of Task Automation","2026-03-25T16:25:06.513026+00:00",{"id":89,"slug":90,"title":91,"created_at":92},"045d1abc-190d-4594-8c95-91e2a26f0c5a","googles-2026-ai-agent-report-decoded-en","Google’s 2026 AI Agent Report, Decoded","2026-03-26T11:15:23.046616+00:00",{"id":94,"slug":95,"title":96,"created_at":97},"e64aba21-254b-4f93-aa21-837484bb52ec","kimi-k25-review-stronger-still-not-legend-en","Kimi K2.5 review: stronger, still not a legend","2026-03-27T07:15:55.385951+00:00",{"id":99,"slug":100,"title":101,"created_at":102},"30dfb781-a1b2-4add-aebe-b3df40247c37","claude-code-controls-mac-desktop-en","Claude Code now controls your Mac desktop","2026-03-28T03:01:59.384091+00:00",{"id":104,"slug":105,"title":106,"created_at":107},"254405b6-7833-4800-8e13-f5196deefbe6","cloudflare-100x-faster-ai-agent-sandbox-en","Cloudflare’s 100x Faster AI Agent Sandbox","2026-03-28T03:09:44.356437+00:00",{"id":109,"slug":110,"title":111,"created_at":112},"04f29b7f-9b91-4306-89a7-97d725e6e1ba","openai-backs-isara-agent-swarm-bet-en","OpenAI backs Isara’s agent-swarm bet","2026-03-28T03:15:27.849766+00:00",{"id":114,"slug":115,"title":116,"created_at":117},"3b0bf479-e4ae-4703-9666-721a7e0cdb91","openai-plan-automated-ai-researcher-en","OpenAI’s plan for an automated AI researcher","2026-03-28T03:17:42.312819+00:00",{"id":119,"slug":120,"title":121,"created_at":122},"fe91bce0-b85d-4efa-a207-24ae9939c29f","harness-engineering-ai-agent-reliability-2026","Harness Engineering: From Bridle to Operating System, The Missing Link in AI Agent Reliability","2026-03-31T06:36:55.648751+00:00",{"id":124,"slug":125,"title":126,"created_at":127},"67dc66da-ca46-4aa5-970b-e997a39fe109","openai-codex-plugin-claude-code-en","OpenAI puts Codex inside Claude Code","2026-04-01T09:21:55.381386+00:00",{"id":129,"slug":130,"title":131,"created_at":132},"7a09007d-820f-43b3-8607-8ad1bfcb94c8","mcp-explained-from-prompts-to-production-en","MCP Explained: From Prompts to Production","2026-04-01T09:24:40.089177+00:00"]