{"id":21,"date":"2026-11-08T13:15:53","date_gmt":"2026-11-08T13:15:53","guid":{"rendered":"http:\/\/blog.antpython.net\/?p=21"},"modified":"2026-11-08T13:15:53","modified_gmt":"2026-11-08T13:15:53","slug":"prompt-%e5%b7%a5%e7%a8%8b%ef%bc%9a%e8%ae%a9%e5%a4%a7%e6%a8%a1%e5%9e%8b%e7%a8%b3%e5%ae%9a%e8%be%93%e5%87%ba%e7%bb%93%e6%9e%84%e5%8c%96%e7%bb%93%e6%9e%9c","status":"publish","type":"post","link":"http:\/\/blog.antpython.net\/?p=21","title":{"rendered":"Prompt \u5de5\u7a0b\uff1a\u8ba9\u5927\u6a21\u578b\u7a33\u5b9a\u8f93\u51fa\u7ed3\u6784\u5316\u7ed3\u679c"},"content":{"rendered":"<p>\u540c\u6837\u4e00\u4e2a\u6a21\u578b\uff0c\u63d0\u793a\u8bcd\u5199\u5f97\u597d\u4e0d\u597d\uff0c\u6548\u679c\u80fd\u5dee\u4e00\u4e2a\u6570\u91cf\u7ea7\u3002\u505a\u4ea7\u54c1\u65f6\uff0c\u76ee\u6807\u5f80\u5f80\u662f\uff1a<strong>\u7a33\u5b9a\u4ea7\u51fa\u53ef\u89e3\u6790\u7684 JSON\/Markdown<\/strong>\uff0c\u800c\u4e0d\u662f\u4e00\u6b21\u6f02\u4eae\u7684\u6563\u6587\u3002<\/p>\n<h2>\u597d Prompt \u7684\u9aa8\u67b6<\/h2>\n<ol>\n<li>\u89d2\u8272\uff1a\u4f60\u662f\u8c01<\/li>\n<li>\u4efb\u52a1\uff1a\u8981\u5e72\u4ec0\u4e48<\/li>\n<li>\u7ea6\u675f\uff1a\u4e0d\u80fd\u5e72\u4ec0\u4e48<\/li>\n<li>\u683c\u5f0f\uff1a\u8f93\u51fa\u957f\u4ec0\u4e48\u6837<\/li>\n<li>\u793a\u4f8b\uff1a\u7ed9 1\uff5e2 \u4e2a\u6b63\u4f8b<\/li>\n<\/ol>\n<h2>\u793a\u4f8b\uff1a\u62bd\u53d6\u7b80\u5386\u5173\u952e\u5b57\u6bb5<\/h2>\n<pre><code>\u4f60\u662f\u4fe1\u606f\u62bd\u53d6\u52a9\u624b\u3002\u4ece\u7528\u6237\u6587\u672c\u4e2d\u63d0\u53d6\u5b57\u6bb5\uff0c\u53ea\u8f93\u51fa JSON\uff0c\u4e0d\u8981\u89e3\u91ca\u3002\n\u5b57\u6bb5\uff1aname, years, skills(array), summary\n\u82e5\u7f3a\u5931\u8bf7\u586b null\u3002\n\n\u793a\u4f8b\u8f93\u5165\uff1a\u5f20\u4e09\uff0c5\u5e74Python\uff0c\u64c5\u957f\u722c\u866b\u4e0e\u6570\u636e\u5206\u6790\u3002\n\u793a\u4f8b\u8f93\u51fa\uff1a{\"name\":\"\u5f20\u4e09\",\"years\":5,\"skills\":[\"Python\",\"\u722c\u866b\",\"\u6570\u636e\u5206\u6790\"],\"summary\":\"5\u5e74Python\u5f00\u53d1\"}\n\n\u73b0\u5728\u5904\u7406\uff1a\n\"\"\"\n{{\u7528\u6237\u6587\u672c}}\n\"\"\"\n<\/code><\/pre>\n<h2>\u63d0\u9ad8\u7a33\u5b9a\u6027\u7684\u6280\u5de7<\/h2>\n<ul>\n<li>\u8981\u6c42\u300c\u53ea\u8f93\u51fa JSON\u300d\uff0c\u5e76\u5728\u4ee3\u7801\u91cc\u505a\u89e3\u6790\u91cd\u8bd5<\/li>\n<li>\u628a\u679a\u4e3e\u503c\u5199\u6b7b\uff1a\u72b6\u6001\u53ea\u80fd\u662f A\/B\/C<\/li>\n<li>\u590d\u6742\u4efb\u52a1\u62c6\u6210\u591a\u6b65\uff1a\u5148\u5206\u7c7b\uff0c\u518d\u62bd\u53d6\uff0c\u518d\u6821\u9a8c<\/li>\n<li>\u5173\u952e\u4e1a\u52a1\u52a0\u89c4\u5219\u6821\u9a8c\uff08\u65e5\u671f\u683c\u5f0f\u3001\u91d1\u989d\u8303\u56f4\uff09<\/li>\n<\/ul>\n<h2>Python \u4fa7\u6821\u9a8c<\/h2>\n<pre><code>import json\nfrom jsonschema import validate\n\nschema = {\n  \"type\": \"object\",\n  \"required\": [\"name\", \"skills\"],\n  \"properties\": {\n    \"name\": {\"type\": [\"string\", \"null\"]},\n    \"skills\": {\"type\": \"array\", \"items\": {\"type\": \"string\"}},\n  },\n}\n\ndef parse_llm_json(text: str):\n    data = json.loads(text)\n    validate(data, schema)\n    return data\n<\/code><\/pre>\n<p>\u6a21\u578b\u8d1f\u8d23\u751f\u6210\uff0c\u4ee3\u7801\u8d1f\u8d23\u9a8c\u6536\u2014\u2014\u8fd9\u662f\u4e0a\u7ebf\u7ea7 Prompt \u5de5\u7a0b\u7684\u6838\u5fc3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u6837\u4e00\u4e2a\u6a21\u578b\uff0c\u63d0\u793a\u8bcd\u5199\u5f97\u597d\u4e0d\u597d\uff0c\u6548\u679c\u80fd\u5dee\u4e00\u4e2a\u6570\u91cf\u7ea7\u3002\u505a\u4ea7\u54c1\u65f6\uff0c\u76ee\u6807\u5f80\u5f80\u662f\uff1a\u7a33\u5b9a\u4ea7\u51fa\u53ef\u89e3\u6790\u7684 JSON\/Mark [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-21","post","type-post","status-publish","format-standard","hentry","category-llm"],"_links":{"self":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts\/21","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=21"}],"version-history":[{"count":0,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts\/21\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}